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



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


1PCS NEW BRAND FESTO Solenoid Valve MEH-5/3G-1/8-B picture

1PCS NEW BRAND FESTO Solenoid Valve MEH-5/3G-1/8-B

$109.56



1pcs New CKD Solenoid Valve F3000-8-W-F picture

1pcs New CKD Solenoid Valve F3000-8-W-F

$32.02



1pcs Brand new NORGREN 59.70061  Solenoid Valve picture

1pcs Brand new NORGREN 59.70061 Solenoid Valve

$177.56



1pcs New YUKEN Solenoid Valve DSG-01-3C4-D24-N1-51T picture

1pcs New YUKEN Solenoid Valve DSG-01-3C4-D24-N1-51T

$142.63



SA-3786-12 603350 Fuel Shutoff Solenoid Kubota Compatible 721D2 21HP Grasshopper picture

SA-3786-12 603350 Fuel Shutoff Solenoid Kubota Compatible 721D2 21HP Grasshopper

$30.24



Cole Hersee (24059-BP) 12V Insulated SPST Continuous Duty Solenoid picture

Cole Hersee (24059-BP) 12V Insulated SPST Continuous Duty Solenoid

$28.89







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