Ads
Ads

Reputation: 6691

How to convert varchar from sql server to Image in android

We have image stored in SQL Server as blob or varchar which is something similar to:

0xFFD8FFE000104A46494600010100000...(Goes till 1945 characters).

How do I convert this to an image for imageview? Do i need to convert it into byte array or Base64?

Upvotes: 1

Views: 525

Answers (2)

Michael Butscher
Michael Butscher

Reputation: 10959

This seems to be a sequence of hexadecimal values. To convert to a byte array, strip off the "0x" at beginning, subdivide string in double character strings ("FF", "D8", "FF") and convert each to a byte by using (byte) Integer.parseInt(s, 16).

Which image data format was used to store the image initially you must find out for yourself then.

Upvotes: 2

Emmanuel
Emmanuel

Reputation: 13223

When I stored a BLOB in sqlite I saved it as a byte[]. Most people would suggest that you should save a reference to a path to where the picture is saved (I think this is mostly for local files). Maybe you can still use this approach and store a string representation of an URL to where the pic is stored in your server and then download it asynchronously.

Upvotes: 0

Related Questions