BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 09-06-2007, 03:50 AM   #1 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default how to get a bitmap into byte[] ?

Please Login to Remove!

i have a bitmap that i aquire programmatically.
I'd like to send the bitmap as an attachment.

How do i get the bitmap into the required byte[] format of SupportedAttachmentPart ?
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 09-06-2007, 04:18 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi simon.hain,

You can use "net.rim.device.api.system.EncodedImage" to get byte[] from Bitmap.

Cheers,
ARIF
Offline  
Old 09-06-2007, 04:25 AM   #3 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

could you provide me a short example?

EncodedImage reads:
To decode an image, first call EncodedImage.createEncodedImage to generate an instance of EncodedImage, and then call getBitmap.

createEncodedImage wants a byte-array - which i don't have.
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 09-06-2007, 07:29 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi simon.hain,

Quote:
Originally Posted by simon.hain View Post
EncodedImage reads:
To decode an image, first call EncodedImage.createEncodedImage to generate an instance of EncodedImage, and then call getBitmap.

createEncodedImage wants a byte-array - which i don't have.
Here is a sample code:
Code:
// Creates an EncodedImage from provided name resource
EncodedImage image = EncodedImage.getEncodedImageResource("logo.bmp");
// Returns a byte array containing the encoded data for this EncodedImage
byte[] array = image.getData();
// Decodes the image represented by this EncodedImage and returns a Bitmap
Bitmap LOGO_BMP = image.getBitmap();
Cheers,
ARIF
Offline  
Old 09-06-2007, 07:41 AM   #5 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

first of all, thank you for your patience.
my problem with using your example code is that i can't provide my bitmap as a resource. I read it from an external source, like
Bitmap bmp = getBitmap();

now i get the error:
cannot find symbol
symbol : method getEncodedImageResource(net.rim.device.api.system. Bitmap)

is there a way i can provide my new bitmap as a named resource?

Quote:
Originally Posted by arifzaman View Post
Hi simon.hain,
Here is a sample code:
Code:
// Creates an EncodedImage from provided name resource
EncodedImage image = EncodedImage.getEncodedImageResource("logo.bmp");
// Returns a byte array containing the encoded data for this EncodedImage
byte[] array = image.getData();
// Decodes the image represented by this EncodedImage and returns a Bitmap
Bitmap LOGO_BMP = image.getBitmap();
Cheers,
ARIF
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 09-06-2007, 11:37 PM   #6 (permalink)
Thumbs Must Hurt
 
Rose's Avatar
 
Join Date: Nov 2006
Location: India
Model: 9700
OS: Windows 7
Carrier: Airtel
Posts: 121
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by simon.hain View Post
first of all, thank you for your patience.
my problem with using your example code is that i can't provide my bitmap as a resource. I read it from an external source, like
Bitmap bmp = getBitmap();

now i get the error:
cannot find symbol
symbol : method getEncodedImageResource(net.rim.device.api.system. Bitmap)

is there a way i can provide my new bitmap as a named resource?
Can you describe clearly what you mean as external resource..From where you are reading the bitmap and how ?

If it is a file you will be reading as byte[]. So you can create a Encoded Image from that byte array and bitmap from that Encoded Image.

What actually the function getBitmap() do ?
Offline  
Old 09-07-2007, 02:11 AM   #7 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

i am using a function of the Linea SCP SDK:
Code:
 Bitmap bmp = dsc.GetSignatureDataScreenBMP();
unfortunately there is no information about this function in the mentioned SDK.
I'd love to use EncodedImage etc but all functions of the RIM API seem to need a resource, not just an object.


Quote:
Originally Posted by Rose View Post
Can you describe clearly what you mean as external resource..From where you are reading the bitmap and how ?

If it is a file you will be reading as byte[]. So you can create a Encoded Image from that byte array and bitmap from that Encoded Image.

What actually the function getBitmap() do ?
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 05-19-2008, 11:24 AM   #8 (permalink)
Knows Where the Search Button Is
 
Join Date: Jul 2007
Model: 8300
PIN: N/A
Carrier: AT&T
Posts: 25
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Simon,

How did you end up solving your problem? I may have a similar one. Accessing the data (i.e. byte[] data) from a bitmap that is drawn on the screen, not from resources.

Thanks
Offline  
Old 05-20-2008, 02:30 AM   #9 (permalink)
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

i just looked up my code, been a while and i am not sure if it worked correctly:

Code:
 /**
* 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(i);
                dos.flush();
                //l++; 
                }
             } 
         bos.flush();
         return bos.toByteArray(); 
       } catch (Exception ex) {
            Dialog.alert("getBytesFromBitmap: " + ex.toString()); return null; } 
}
__________________
java developer, Devinto, hamburg/germany
Offline  
Old 07-14-2008, 09:54 AM   #10 (permalink)
Talking BlackBerry Encyclopedia
 
Smiley8's Avatar
 
Join Date: May 2008
Location: Calgary, AB
Model: Torch
Carrier: Fido
Posts: 226
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by simon.hain View Post
i just looked up my code, been a while and i am not sure if it worked correctly:

Code:
 /**
* 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(i);
                dos.flush();
                //l++; 
                }
             } 
         bos.flush();
         return bos.toByteArray(); 
       } catch (Exception ex) {
            Dialog.alert("getBytesFromBitmap: " + ex.toString()); return null; } 
}
i'm having problem saving the bytes and and recreating the bitmap using this function.

here is what i my code
Code:

 _bytes = getBytesFromBitmap(_mybitmap);

 Bitmap _bmap = new Bitmap(Bitmap.ROWWISE_16BIT_COLOR , 32, 32, _bytes) ;
graphics.drawBitmap(1,30, 32, 32, _bmap, 0, 0);
is this the correct way of creating the bitmap? when it display it does not show the same bitmap.
__________________
Visit our website www.toysoft.ca for Cool BlackBerry Apps.

Follow us @ http://twitter.com/toysoft
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.