0

I am a nooby android developer and am trying to convert bitmap image into byte array and store that value in Mysql database.

The following code is working great and the value is stored in the database, but am not sure if this is the real image or not..

Here's the code am using to convert the image:

Bitmap bitmap = BitmapFactory.decodeFile(file_path);
         ByteArrayOutputStream blob = new ByteArrayOutputStream();
         bitmap.compress(CompressFormat.JPEG,100, blob);

         bitmapdata = blob.toByteArray();

         //System.out.println(blob.toByteArray());

         bitmap.recycle();
         bitmap = null;

         photo_string = bitmapdata.toString();
         System.out.print(photo_string);
         try {
                blob.close();
                blob = null;
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();


}

and here's the HttpPost part:

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("InsertIntoDB.php");
pairs.add(new BasicNameValuePair("img",photo_string ));
post.setEntity(new UrlEncodedFormEntity(pairs));
HttpResponse response = client.execute(post);

The value stored in DB is something like: [B@4285096

is the really the image itself ?? Please help with that.

1 Answer 1

1

Yes. The value you are seeing is the byte array for image.

Sign up to request clarification or add additional context in comments.

12 Comments

Thank you so very much, i spent the whole day checking if it's the byte array or not... :) Thanks
@Izzo32: No it is not. Image data is not stored in db correctly.
Can you show the code how you are reading image data from the database?
but the thing that is saved in db is definately the byte array of a image
But what OP says is value stored in DB is something like: [B@4285096
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.