Android:从MSSQL检索图像
我是Android新手,尝试从MSSQL获取图像并将其设置为背景Android:从MSSQL检索图像,android,sql-server,database,bitmap,bitmapfactory,Android,Sql Server,Database,Bitmap,Bitmapfactory,我是Android新手,尝试从MSSQL获取图像并将其设置为背景 CallableStatement proc = null; String temp2 ="{ call AndroidDB.dbo.getStocks("+ temp +")}"; proc = MainActivity.conn.prepareCall(temp2);
CallableStatement proc = null;
String temp2 ="{ call AndroidDB.dbo.getStocks("+ temp +")}";
proc = MainActivity.conn.prepareCall(temp2);
ResultSet rs = proc.executeQuery();
Bitmap bitmap= null;
byte[] blob =null;
for (int i = 0,j=0; rs.next(); i++ ) {
if(i%3==0){
layout_stocks_h.add(new LinearLayout(this));
(layout_stocks_h.get(j)).setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); // Verbose!
lp.weight = 1.0f;
(layout_stocks_h.get(j)).setLayoutParams(lp);
layout_stocks_v.addView((layout_stocks_h.get(j)));
(layout_stocks_h.get(j)).setId(200+(j));
j++;
}
imagebutton_stocks.add(new ImageButton(this));
blob = rs.getBytes("stokresim");
ByteArrayInputStream imageStream = new ByteArrayInputStream(blob);
bitmap = BitmapFactory.decodeStream(imageStream);
imagebutton_stocks.get(i).setImageBitmap(bitmap);
imagebutton_stocks.get(i).setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
layout_stocks_h.get(j-1).addView(imagebutton_stocks.get(i));
imagebutton_stocks.get(i).setId(250+i);
imagebutton_stocks.get(i).setOnClickListener(this);
noOfStocks = i;
我还尝试使用:
bitmap = BitmapFactory.decodeByteArray(blob , 0, blob.length);
但是,没有任何效果,我的过程工作正常,创建了正确数量的按钮,但没有图像
我将图像文件作为图像存储在MSSQL中,并尝试使用varbinary(MAX)
提前感谢我还尝试使用二进制流blob=rs.getBinaryStream(“stokresim”);位图=BitmapFactory.decodeStream(blob);但没有起作用:(