2012-06-02 71 views
-1

從字節數組到圖像的圖像轉換代碼,即blob。在java中將字節數組轉換爲圖像(blob)

try 
{ 
    Blob image_vis = rs1.getBlob(10); 
    InputStream x=image_vis.getBinaryStream(); 
    OutputStream out=new FileOutputStream(string_op); 
    byte[] bytes = string_op.getBytes(); 
    String s=new String(bytes); 
    System.out.println(+s); //prints bytes for the string 
    ImageIcon icon_cap = new ImageIcon(string_op); 
    image_cap.setIcon(icon_cap); //prints nothing to Jlabel 
    //image_cap.setText(s); //prints a path of a image 
    } 

我能夠得到的圖像的路徑,但我ANABLE將其轉換成圖像格式,這樣它會顯示在窗體上。請幫幫我。

+2

請不要重複你的問題。 http://stackoverflow.com/questions/10849893/javahow-to-convert-byte-array-to-blob –

+0

我無法找到解決方案,這就是爲什麼.... :( – Anjali

回答

2

試試這個..

try 
{ 
Blob image_vis = rs1.getBlob("blobColumn"); 
int blobLength = (int) image_vis.length(); 

byte[] bytes = image_vis.getBytes(1, blobLength); 
image_vis.free(); 
final BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(bytes)); 
ImageIO.write(bufferedImage, "jpg", new File("ImagePath/ImageName.jpg")); 
} 

稍後,您可以拿起圖像..

相關問題