나비BOS가 개발한--사진 업로드 코드


  
  
  
  
  1. import com.kingdee.eas.hr.emp.client.PhotoPanel;  
  2. import java.awt.image.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[] imageToBytes(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입니다.

좋은 웹페이지 즐겨찾기