1. import com.kingdee.eas.hr.emp.client.PhotoPanel;  
  2. import java.awt.p_w_picpath.BufferedImage;  
  3.  
  4. public class RentVehicleEditUI extends AbstractRentVehicleEditUI {  
  5. private static final Logger logger = CoreUIObject  
  6. .getLogger(RentVehicleEditUI.class);  
  7.  
  8. // 用于存放当前修改的记录的number,方便判断用户修改过number没有  
  9. String tempNumber = "";  
  10.  
  11. // 作用同上,存放×××号码  
  12. String tempIdentityNo = "";  
  13.  
  14. PhotoPanel photoPanel = new PhotoPanel();  
  15.  
  16. BufferedImage bufferedImage = null;  
  17.  
  18. /**  
  19. output class constructor  
  20. */  
  21. public RentVehicleEditUI() throws Exception {  
  22. super();  
  23. }  
  24.  
  25. /**  
  26. output loadFields method  
  27. */  
  28. public void loadFields() {  
  29. super.loadFields();  
  30. // 将当前打开的信息的number记录下来,方便后面判断是否改过该记录  
  31. tempNumber = this.editData.getNumber();  
  32. tempIdentityNo = this.editData.getIdentityNo();  
  33. this.initPhotoPanel();// 初始化图片显示区  
  34. if (this.oprtState.equals(OprtState.ADDNEW)) {  
  35. photoPanel.setSelectImage(null);  
  36. photoPanel.repaint();  
  37. else {  
  38. try {  
  39. this.loadImage();// 加载图片  
  40. } catch (Exception e) {  
  41. // MsgBox.showWarning("加载图像失败!");  
  42. e.printStackTrace();  
  43. }  
  44. }  
  45.  
  46. }  
  47.  
  48. // 初始化图片显示区  
  49. private void initPhotoPanel() {  
  50.  
  51. photoPanel.setOprtStat("ADD");  
  52. photoPanel.setBounds(627, 117, 169, 150);  
  53. photoPanel.setBackground(Color.ORANGE);  
  54. this.add(photoPanel);  
  55. }  
  56.  
  57. // 在非新增状态下加载已经存储的图片  
  58. private void loadImage() throws Exception {  
  59. IRentVehicle irentVehicle = RentVehicleFactory.getRemoteInstance();  
  60. RentVehicleInfo rentVehicleInfo = null;  
  61.  
  62. try {  
  63. rentVehicleInfo = irentVehicle  
  64. .getRentVehicleInfo("select driverPhoto where id =" + "'" 
  65. + this.editData.getId() + "'"); // select 
  66. // DriverPhoto  
  67. } catch (ObjectNotFoundException e) {  
  68. MsgBox.showInfo("照片不存在");  
  69. SysUtil.abort();  
  70. }  
  71. if (!rentVehicleInfo.isEmpty()) {  
  72. byte[] byteArray = rentVehicleInfo.getDriverPhoto();  
  73. ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(  
  74. byteArray);  
  75. bufferedImage = ImageIO.read(byteArrayInputStream);  
  76. photoPanel.setSelectImage(bufferedImage);  
  77. byteArrayInputStream.close();  
  78. photoPanel.repaint();  
  79. }  
  80.  
  81. }  
  82.  
  83. // 图片转化为二进制文件  
  84. public byte[] p_w_picpathToBytes(File file) {  
  85.  
  86. if (this.oprtState.equals(OprtState.ADDNEW)) {  
  87. // if(file==null){  
  88. // MsgBox.showWarning("没有添加司机照片!");  
  89. // }  
  90. }  
  91. if (file != null) {  
  92. int size = (int) file.length();  
  93. FileInputStream fin = null;  
  94. try {  
  95. fin = new FileInputStream(file);  
  96. } catch (FileNotFoundException e) {  
  97. e.printStackTrace();  
  98. }  
  99. byte[] bts = null;  
  100. if (size > 0) {  
  101. bts = new byte[size];  
  102. try {  
  103. fin.read(bts);  
  104. } catch (IOException e) {  
  105. e.printStackTrace();  
  106. }  
  107. return bts;  
  108. }  
  109. }  
  110. return null;  

另外,在实体中新增该属性,类型为ByteArray

对应的表中的字段类型为BLOB。