|
|
09-06-2007, 03:50 AM
|
#1
|
CrackBerry Addict
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
|
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
|
|
09-06-2007, 04:18 AM
|
#2
|
Thumbs Must Hurt
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
|
Hi simon.hain,
You can use "net.rim.device.api.system.EncodedImage" to get byte[] from Bitmap.
Cheers,
ARIF
|
Offline
|
|
09-06-2007, 04:25 AM
|
#3
|
CrackBerry Addict
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
|
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
|
|
09-06-2007, 07:29 AM
|
#4
|
Thumbs Must Hurt
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
|
Hi simon.hain,
Quote:
Originally Posted by simon.hain
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
|
|
09-06-2007, 07:41 AM
|
#5
|
CrackBerry Addict
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
|
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
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
|
|
09-06-2007, 11:37 PM
|
#6
|
Thumbs Must Hurt
Join Date: Nov 2006
Location: India
Model: 9700
OS: Windows 7
Carrier: Airtel
Posts: 121
|
Quote:
Originally Posted by simon.hain
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
|
|
09-07-2007, 02:11 AM
|
#7
|
CrackBerry Addict
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
|
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
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
|
|
05-19-2008, 11:24 AM
|
#8
|
Knows Where the Search Button Is
Join Date: Jul 2007
Model: 8300
PIN: N/A
Carrier: AT&T
Posts: 25
|
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
|
|
05-20-2008, 02:30 AM
|
#9
|
CrackBerry Addict
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
|
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
|
|
07-14-2008, 09:54 AM
|
#10
|
Talking BlackBerry Encyclopedia
Join Date: May 2008
Location: Calgary, AB
Model: Torch
Carrier: Fido
Posts: 226
|
Quote:
Originally Posted by simon.hain
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.
|
Offline
|
|
|
|