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

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

Help with Bitmap object

[ Edited ]

Hi all, 

 

I have a loop which is looping through square areas of a bitmap from left to right - top to bottom and comparing that area with lastBitmap - if this square area is different/has changed it is sent over the socket to client.

 

My code is really quite slow and I'm trying to find out why. I then found this thread..

 

http://supportforums.blackberry.com/t5/Java-Development/setARGB-causes-Bitmap-to-be-drawn-slower/td-...

 

I am using same calls as op in that thread - setARGB and getARGB, the reason being I want to get the area that has changed and put this square into lastBitmap so this changed isn't detected again, i will then continue looping the squares of the newBitmap.

 

Can anyone explain if there is a faster way of putting an area of an bitmap into another area of a bitmap please?

 

rect2 = new XYRect(offsetX,offsetY,w, h);
															newBitmap.locateDifference(rect2,lastBitmap, 0, 0);
															
															
															if((rect2.x > 0) || (rect2.y > 0))
															{

																pixels = new int[w*h];
																newBitmap.getARGB(pixels, 0, w, offsetX, offsetY, w, h);
																lastBitmap.setARGB(pixels, 0, w, offsetX, offsetY, w, h);
																sendWidth = w;
																sendHeight = h;
																send = true; 
															}

 

Trusted Contributor
bbdev12345
Posts: 117
Registered: ‎09-06-2011
My Device: 9900

Re: Help with Bitmap object

What is also a big problem when I use setARGB() on lastBitmap is when I try to do further locateDifference processing on the bitmap it never detects any more changes even though there any differences, anyone know why?

 

It's seems I'm somehow breaking the image once I use setARGB() with data from getARGB() on another bitmap but no exceptions are being thrown.

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Help with Bitmap object

Have you thought about putting in some processing to display the Bitmaps and make sure you are correctly picking up the changes? 

Trusted Contributor
bbdev12345
Posts: 117
Registered: ‎09-06-2011
My Device: 9900

Re: Help with Bitmap object

I have followed your suggestion Peter (thanks) and I'm seeing 2 completely different images on my screen and my code (as posted) is telling me there are no more differences.

 

I've been at this all day and can't understand why my code tells me there is no difference after using setARGB ().

Trusted Contributor
bbdev12345
Posts: 117
Registered: ‎09-06-2011
My Device: 9900

Re: Help with Bitmap object

Just to add to the confusion I have just found my second locateDifference call has numerous detections of change one after each other very intermittently, it will then just go back to never detecting changes to obviously different images.

 

Please if someone can give me a hand I have pasted my problematic code (the code checks for difference in a region and if there is difference it sends the difference to buffer and checks for further differences in this frame, it hardly ever tells me there are more differences. Therefore it is always sending changes when there are more changes to detect first.

 

 

else
														{



															rect2 = new XYRect(offsetX,offsetY,w, h);
															newBitmap.locateDifference(rect2,lastBitmap, 0, 0);

															if((rect2.x > 0) || (rect2.y > 0))
															{
																pixels = new int[w*h];
																newBitmap.getARGB(pixels, 0, w, offsetX, offsetY, w, h);
																lastBitmap.setARGB(pixels, 0, w, offsetX, offsetY, w, h);
																sendWidth = w;
																sendHeight = h;
																send = true; 
															}

														}

													}
												}

												if(send)
												{
													send = false;
													pixels3 = integersToBytes(pixels);
													writeToBuffer( out,  dout,  pixels3,  offsetX,  offsetY,  w,  h);
													XYRect rect22 = new XYRect(0,0,lastBitmap.getWidth(), lastBitmap.getHeight());
													final Bitmap newBitmap2 = newBitmap;
													final Bitmap lastBitmap2 = lastBitmap;

													newBitmap2.locateDifference(rect22,lastBitmap2, 0, 0);
													if(true)
													{

														//doOnce = false;
														if((rect22.x > 0) || (rect22.y > 0))//bout.size() > (width * height))
														{
															Log.info(height+" heigth still more changes to be processed width="+width);
														}
														else
														{
															//Log.info(height+" heigth no more changes to be processed width="+width);
															writeBufferToSocket();

														}

													}

												}

 

 

Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: Help with Bitmap object

I've red your post several times and still don't understand your problem. Try working based on the assumption "locateDifference() always works properly"

Trusted Contributor
bbdev12345
Posts: 117
Registered: ‎09-06-2011
My Device: 9900

Re: Help with Bitmap object

Thanks BGmot, I have spent another day on this, currently I am never seeing the first square on the pb of each row I scan on the phone, i get all the other squares in the rows that have changed but not first. So if a screen change happens on the  phone I have the new screen on the pb apart from a strip from top to bottom (first 50 px) of the initial screen.

 

This is obviously a problem but I can't find out why it is doing this - I have rewitten the code multiple times today but this happens still. So I suppose I am now assuming locateDifference is correct and my loop is somehow incorrect.