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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Trusted Contributor
Posts: 117
Registered: ‎09-06-2011
My Device: 9900
My Carrier: myself

Correct code to get area of image data

[ Edited ]

Hi all,

 

I have posted a thread in the native forum because I am struggling to insert new image data into an already displayed image on the playbook. The new and already displayed image data is from bb os as I am taking a screenshot of the bb phone and sending it to the pb.

 

When I grab the new data to be inserted my approach is different from first image because I only want to detect if a certain area of the screen is different so I use locatedifference and getARGB instead of just getting a screenshot and sending its bytes, this time I'm just sending part of image.

 

My problem is that what should be a clear image of the screen with points (0,0,50,50) I am getting an image which is certainly not 50x50 screenshot of the bb top left screen BUT it does represent the colors of the screen im on ie blue, white, black.

 

My code might be wrong for phone side so I'm posting it to see if anybody can confirm it's correct/incorrect - I confused by scanline argument in getARGB for instance so it might be wrong.

 

For the partial image, I am getting the int[] from getARGB(int[],...), converting it to byte[] and then sending these bytes preceded by the number of bytes, all is received well.

 

Anyone see a problem with this code - thank you for reading.

 

int w = 50;
int h = 50;
width = Display.getWidth();
height = Display.getHeight();
  rect = new XYRect(0,0, w, h); int[] pixels = new int[w*h*3];//I have also tried w*h bit = new Bitmap(width, height); Display.screenshot(bit); png=JPEGEncodedImage.
encode(bit, quality); Bitmap bit2 = png.getBitmap(); bit2.getARGB(pixels, 0, width, 0, 0, w, h); byte[] pixels2 = integersToBytes(pixels); dout.writeInt(pixels2.length); out.write(pixels2);

 

 

 

byte[] integersToBytes(int[] values)
{
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   DataOutputStream dos = new DataOutputStream(baos);
   for(int i=0; i < values.length; ++i)
   {
       try
       {
        dos.writeInt(values[i]);
       }
       catch(Exception gg)
       {
           
       }
   }

   return baos.toByteArray();
}

 

Developer
Posts: 1,041
Registered: ‎07-16-2008
My Device: ಠ_ಠ

Re: Correct code to get area of image data

ARGB is one int. It should just be int[w*h].

 

Have you tried converting the int[] back to a bitmap to see if its just the 50x50 section you intended?

Highlighted
Trusted Contributor
Posts: 117
Registered: ‎09-06-2011
My Device: 9900
My Carrier: myself

Re: Correct code to get area of image data

[ Edited ]

sorry mreed for not responding quicker - just having a fight with the simulator to get it consistently output my test files for yourself and BGmot but I now realised I couldn't get past getARGB - so I thought let's check java post (don't get notifications for some reason) and voila you provide the answer for getARGB() illegalargument error - thanks. 

 

Should have them test files posted soon on native forum - just checking a lot of tests as w*h*3 being wrong makes a lot of my attempts in the last couple of days wrong also.

 

p.s just realised the errors with getARGB() were actually because I was providing width of bitmap for scanline argument rather than just the width of the rectangle (50). This is why I haven't noticed it before as I have just been changing it around. so scanline is the width of rectangle.