Get byte[] of image
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi All,
I am working on an app. in which I set some images in gridview.
What I want to do is take the byte[] of any image clicked and store it in DB.
Currently I have stored those images in drawable of the application. I tried "Bitmap bitmap = view.getDrawingCache();", but it is giving bitmap as null.
Can anyone please help me in getting byte[] of the image?
Thanks,
Yash
I am working on an app. in which I set some images in gridview.
What I want to do is take the byte[] of any image clicked and store it in DB.
Currently I have stored those images in drawable of the application. I tried "Bitmap bitmap = view.getDrawingCache();", but it is giving bitmap as null.
Can anyone please help me in getting byte[] of the image?
Thanks,
Yash
yash wardhan
Ranch Hand
Posts: 46
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Any replies on this please.
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
[I am not sure I understood your question fully..]
If you have a handle on a android.graphics.Bitmap, you can write it to a java.lang.ByteArrayOutputStream using the compress method of android.graphics.BitmapFactory class. You can then get the byte array from java.lang.ByteArrayOutputStream object using toByteArray() method.
Something like,
Hope that helps..
If you have a handle on a android.graphics.Bitmap, you can write it to a java.lang.ByteArrayOutputStream using the compress method of android.graphics.BitmapFactory class. You can then get the byte array from java.lang.ByteArrayOutputStream object using toByteArray() method.
Something like,
Hope that helps..
[List of FAQs] | [Android FAQ] | [Samuh Varta]
yash wardhan
Ranch Hand
Posts: 46
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks Monu,
I tried this but the problem is my bm object is null.
Actually I have my images in drawable and I want to get the Bitmap (or byte[]) of the user selected image.
Don't know why object of bitmap is null.
I used getDrawingCache() of view, and I have one more doubt even if this method gives me bitmap, what if any user disables the cache(don't know how to do it though).
Please reply
I tried this but the problem is my bm object is null.
Actually I have my images in drawable and I want to get the Bitmap (or byte[]) of the user selected image.
Don't know why object of bitmap is null.
I used getDrawingCache() of view, and I have one more doubt even if this method gives me bitmap, what if any user disables the cache(don't know how to do it though).
Please reply
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
I'd imagine you can get selected bitmap by having a onItemClickListener on your grid view and overriding the onItemClick method(atleast if you have setup your adapter for grid view like this one here).
[List of FAQs] | [Android FAQ] | [Samuh Varta]
yash wardhan
Ranch Hand
Posts: 46
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Monu,
I tries that solution but may be doing something wrong, can you please post the code.
I tried the same code that you pointed to. I want to convert that byte[] into string and save in DB.
Thanks,
Yash
I tries that solution but may be doing something wrong, can you please post the code.
I tried the same code that you pointed to. I want to convert that byte[] into string and save in DB.
Thanks,
Yash
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Sorry, I haven't coded anything in this regard. I was just making some general suggestions..
Why dont you go ahead and post your code-maybe that would help?
Why dont you go ahead and post your code-maybe that would help?
[List of FAQs] | [Android FAQ] | [Samuh Varta]
yash wardhan
Ranch Hand
Posts: 46
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Yash,
If you understand the purpose of all the functions in your ImageAdapter class and the way Adapters and views work, your problem is solved.
Here's what you can do:
Override the getItem(int position) method of the ImageAdapter class to return the resource Id.
In the onItemClick(..) of your TestGridImages do a getItem on the adapter, this will return the resource Id(remember we did so earlier).Use this resource Id to create a bitmap, then write the bitmap to your ByteArrayOutputStream.
If you understand the purpose of all the functions in your ImageAdapter class and the way Adapters and views work, your problem is solved.
Here's what you can do:
Override the getItem(int position) method of the ImageAdapter class to return the resource Id.
In the onItemClick(..) of your TestGridImages do a getItem on the adapter, this will return the resource Id(remember we did so earlier).Use this resource Id to create a bitmap, then write the bitmap to your ByteArrayOutputStream.
[List of FAQs] | [Android FAQ] | [Samuh Varta]
| The glass is neither half full or half empty. It is too big. But this tiny ad is just right: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |










