BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 09-06-2007, 03:50 AM   #1
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
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
arifzaman
Thumbs Must Hurt
 
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
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
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
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
arifzaman
Thumbs Must Hurt
 
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
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
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
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
Rose
Thumbs Must Hurt
 
Rose's Avatar
 
Join Date: Nov 2006
Location: India
Model: 9700
OS: Windows 7
Carrier: Airtel
Posts: 121
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
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
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
rab1
Knows Where the Search Button Is
 
Join Date: Jul 2007
Model: 8300
PIN: N/A
Carrier: AT&T
Posts: 25
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
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
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
Smiley8
Talking BlackBerry Encyclopedia
 
Smiley8's Avatar
 
Join Date: May 2008
Location: Calgary, AB
Model: Torch
Carrier: Fido
Posts: 226
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch picture

NEW OEM Battery A1466 A1369 A1496 A1405 A1377 A1466 for MacBook Air 13 inch

$35.90



For iPhone 5 5s 6 Plus 6S 6 6S Plus 7 8 Plus LCD Display+ Touch Replacement OEM picture

For iPhone 5 5s 6 Plus 6S 6 6S Plus 7 8 Plus LCD Display+ Touch Replacement OEM

$29.88



NEW OEM A1618 Battery for Apple MacBook Pro 15” Retina 99.5Wh A1398 Mid 2015 picture

NEW OEM A1618 Battery for Apple MacBook Pro 15” Retina 99.5Wh A1398 Mid 2015

$49.90



OEM Battery for MacBook Pro 17

OEM Battery for MacBook Pro 17" A1309 A1297 Early 2009 Mid 2009 2010 MC226

$42.80



A1417 OEM Battery for Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013 US picture

A1417 OEM Battery for Apple Macbook Pro 15 Retina A1398 Mid 2012 Early 2013 US

$45.90



A1618 NEW OEM Battery for MacBook Pro 15

A1618 NEW OEM Battery for MacBook Pro 15" Retina A1398 Mid 2015 020-00079

$49.90







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