在iageView android中没有显示位图图像? [英] Bitmap Image is not showing in iageView android?
本文介绍了在iageView android中没有显示位图图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
图像存储在Microsoft SQL Server中,我可以轻松地将其检索为字符串但不能在imageVuew中显示
我得到的图像字符串是0x433A5C55736572735C4D616E736F6F725C50696374757265732E436170747572652E4A5047
The Image is stored in Microsoft SQL Server and I am easily able to retrieve it andriod as string but can't display it in imageVuew
The Image String Which I get is 0x433A5C55736572735C4D616E736F6F725C50696374757265732E436170747572652E4A5047
//This is the image string I get from db and it dispalys fine in text view
imageString= resultString.getProperty(7).toString();
//This is how I try to show it in imageview
ImageView iv= (ImageView) findViewById(R.id.ivProfilePic);
byte[] imgBytes = Base64.decode(imagestring, Base64.DEFAULT);
final Bitmap bitmap = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length);
iv.setImageBitmap(bitmap);
推荐答案
需要查看图片插入代码。创建表时,您的代码如下:
Need to see your image insertion code. While creating table do you code like:
CREATE TABLE [dbo].[ImgTbl2](
..........
[ImgName] [nvarchar](50) NULL,
[Img] [nvarchar](max) NULL
)
然后在插入图像之前:
And then before insert your image:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
originBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byteArray = stream.toByteArray();
encodedImage = Base64.encodeToString(byteArray, Base64.DEFAULT);
插入时:
While inserting:
String commands = "Insert into ImgTbl2 (ImgName,Img) values ('"
+ imageName.getText().toString() + "','" + encodedImage
+ "')";
如果所有这些都是正确的,那么您的代码将会正常运行。
更多:
Android在MS SQL Server中存储图像 [ ^ ]
如何在/从SQLServer存储/检索图像 [ ^ ]
这篇关于在iageView android中没有显示位图图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文