Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport
Accepted Solution

can bitmap be saved to persistent store?

Quote from the previous forums:


Smiley

Posts: 29
From: Canada
Registered: May, 2008

can bitmap be saved to persistent store?
Posted: Jul 14, 2008 12:41 PM
Reply
I'm trying to save a bitmap to persistent store and getting an error msg saying Bitmap is not persistable.

is there a way to save a bitmap?

thanks


Yes this is possible.  You can use the Bitmap.getARGB method to obtain a byte array of the Bitmap.  Then store its contents in a ByteVector.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
smiley
Posts: 1,497
Registered: ‎07-14-2008
My Device: Z10

Re: can bitmap be saved to persistent store?

once i saved the data can i use this to display it again?

 

Bitmap _bmap = new Bitmap(Bitmap.ROWWISE_16BIT_COLOR , 32, 32, _bitmap_data) ;
graphics.drawBitmap(0,0, 32, 32, _bmap, 0, 0);                              
 

thanks 

BlackBerry Development Advisor
MSohm
Posts: 14,753
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: can bitmap be saved to persistent store?

Assuming you extracted _bitmap_data from the ByteVector, then yes this should work.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
smiley
Posts: 1,497
Registered: ‎07-14-2008
My Device: Z10

Re: can bitmap be saved to persistent store?

after creating the new bitmap with the data all i got is a blue bitmap.

here is the code that gets the bitmap data and recreate it.

 

 

scaledImg - is a bitmap that is resized to 32 x 32

Bitmap _bmap = new Bitmap( Bitmap.ROWWISE_16BIT_COLOR, 32, 32, getBytesFromBitmap(scaledImg)) ;

_graphics.drawBitmap(1,1, 32, 32, _bmap, 0, 0);


/**
* this function was written by someone else
*
* Receive bytearray containing the pixel positions of a bitmap which are painted.
* @param bmp Bitmap to receive painted pixels
* @return Bytearray of numbers with positions of painted pixels */


public byte[] getBytesFromBitmap(Bitmap bmp) {
try {
int height=bmp.getHeight();
int width=bmp.getWidth();
int[] rgbdata = new int[width*height];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
//Graphics g = new Graphics(bmp);
bmp.getARGB(rgbdata,0,width,0,0,width,height);

for (int i = 0; i < rgbdata.length ; i++) {
if (rgbdata[i] != -1)
{
dos.writeInt(rgbdata[i]);
dos.flush();
}
}
bos.flush();
return bos.toByteArray();
} catch (Exception ex) {
return null; }
}

 

 

Developer
Berrysoft
Posts: 143
Registered: ‎07-14-2008
My Device: Not Specified

Re: can bitmap be saved to persistent store?

Why on Earth would you store a Bitmap which is a large resource to the persistent store?  Memory is at a premium, and I personnally wouldn't want software that wastes storage like this on my Blackberry.  Put the Bitmap on the SD card (or just as a resource in the software) and just store an int (if anything is needed) to tell you which bitmap the user has selected.

 

New Developer
Neil
Posts: 11
Registered: ‎07-14-2008
My Device: Not Specified

Re: can bitmap be saved to persistent store?

[ Edited ]

There are a number of reasons why you might want to store a Bitmap in a persistent store. One is if you know the images are small and so would not put a big burden on memory and you need perform quick-lookups (hitting your persistent store in memory is quicker than hitting the SDCard). The other is to avoid coherency issues where you have to keep your internal records of where images are stored consistent with what is on the SDCard. ie. If a user decides to move pictures around on the SDCard the user-experience in your application suffers as you have to re-validate everything.

 

Also, your suggestion to store the picture as a resource in the software suffers from the same problem you're trying to mitigate. Since application software on the BlackBerry is stored in the same memory space as the persistent stores, both approaches take a equal hit in the same playground.

Message Edited by Neil on 07-15-2008 12:44 PM
Developer
smiley
Posts: 1,497
Registered: ‎07-14-2008
My Device: Z10

Re: can bitmap be saved to persistent store?

if you ever worked with large images and try to resize them to a thumbnail you would understand why i want to save the bitmap bits.  currently when my app queries the sd card for pictures i generate a thumbnail for each picture. (now imagine a list over 500 pics)  that is what i want to save.  by saving the thumbnail you do not have to resize the image each time the user scrolls the page.

 

if you have a better solution please let me know. 

Developer
Berrysoft
Posts: 143
Registered: ‎07-14-2008
My Device: Not Specified

Re: can bitmap be saved to persistent store?

Neil,

 

I agree with the problems you site, but depending on the memory involved, would be worth it IMHO.  Also, the program itself (and hence it's resources) are not in the persisent store, just memory right?  In other words, there is memory, then there is the more limited memory which is persistent.  I lack any info on the details of the hardware, and if anyone knows that would be enlightening.

 

Is persistent store implemented as a PROM... how, etc?

 

Developer
Berrysoft
Posts: 143
Registered: ‎07-14-2008
My Device: Not Specified

Re: can bitmap be saved to persistent store?

I'm aware of the problem, and would use a solution like the one implemented by MiuTunes.  Basically, generate the thumbnails up front, and store them on the SD card.

 

As neil says, there is a small performance lag, compared, but I personally don't find it unacceptable in that application.  Not sure what you are developing, and perhaps there are times when in-memory is best.  I was also assuming (incorrectly?) that you were going to leave them in persistent store after your app terminates.  Anyway, Neil knows more about this than I do.

 

Developer
smiley
Posts: 1,497
Registered: ‎07-14-2008
My Device: Z10

Re: can bitmap be saved to persistent store?

[ Edited ]
How do i set this thread to be solved?
Message Edited by smiley on 07-16-2008 08:39 AM