Bootstrap

将数据库中取出的blob显示为图片

1、得到blob,如何得到就不细说了

Blob blob = getblob();
BufferedInputStream inputimage=null;
try {
	inputimage = new BufferedInputStream(blob.getBinaryStream());
} catch (SQLException e1) {
                e1.printStackTrace();
}

 2、转化为Image

try{
ImageData idata = new ImageData(inputimage);
Image img = new Image(null, idata);
ComponentImgDialog dlg = new ComponentImgDialog(new Shell());
dlg.setImage(img);
dlg.open();
										}
catch(Exception e2){
	System.out.println(e2);
}

 3、画到Canvas上

final Canvas canvas = new Canvas(topComp, SWT.NONE);
Rectangle rect = img.getBounds();
canvas.setBounds(0, 0, rect.width, rect.height);
canvas.setBackgroundImage(img);

 

;