11-05-2012 09:52 AM - edited 11-05-2012 09:53 AM
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..
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;
}
11-05-2012 04:42 PM
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.
11-05-2012 06:41 PM
Have you thought about putting in some processing to display the Bitmaps and make sure you are correctly picking up the changes?
11-05-2012 07:23 PM
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 ().
11-05-2012 09:32 PM
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();
}
}
}
11-06-2012 12:57 PM
I've red your post several times and still don't understand your problem. Try working based on the assumption "locateDifference() always works properly"
11-06-2012 02:41 PM
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.