This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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?
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).
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).
Joined: Jan 22, 2008
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.
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.