Click here to Skip to main content
15,878,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Java
//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);
Posted
Updated 17-Dec-15 3:21am
v2

1 solution

Need to see your image insertion code. While creating table do you code like:
SQL
CREATE TABLE [dbo].[ImgTbl2](
    ..........
    [ImgName] [nvarchar](50) NULL,
    [Img] [nvarchar](max) NULL
)


And then before insert your image:
C#
ByteArrayOutputStream stream = new ByteArrayOutputStream();
originBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byteArray = stream.toByteArray();
encodedImage = Base64.encodeToString(byteArray, Base64.DEFAULT);


While inserting:
C#
String commands = "Insert into ImgTbl2 (ImgName,Img) values ('"
                    + imageName.getText().toString() + "','" + encodedImage
                    + "')";

If all of them are correct, you code will work good.
More:
Android Storing Images in MS SQL Server[^]
How to store/retrieve image to/from SQLServer[^]
 
Share this answer
 
v3
Comments
Member 10528646 17-Dec-15 14:03pm    
I am using microsoft sql server database where blob does not exist and am trying to retrieve it using ksoap
ridoy 17-Dec-15 15:54pm    
Check edited answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900