grabscreen "Invalid pixel rectangle"
Monkey Forums/Monkey Bug Reports/grabscreen "Invalid pixel rectangle"
| ||
this works in release mode but not in debug mode.if i call the function as below. grabscreen(100, 100, 200, 200) Function grabscreen:Int(gs_x:Int, gs_y:int, SCREEN_WIDTH2:int, SCREEN_HEIGHT2:int) scrshot = CreateImage(SCREEN_WIDTH2, SCREEN_HEIGHT2) Local pixels:Int[] = New Int[SCREEN_WIDTH2 * SCREEN_HEIGHT2] ReadPixels(pixels, gs_x, gs_y, SCREEN_WIDTH2, SCREEN_HEIGHT2) scrshot.WritePixels(pixels, gs_x, gs_y, SCREEN_WIDTH2, SCREEN_HEIGHT2) DrawImage(scrshot, 100, 100) Return 0 End in debug mode it fails and tells me error in line 126 of graphics.monkey which is the line below. If x<0 Or y<0 Or x+width>Self.width Or y+height>Self.height Error "Invalid pixel rectangle" All im doing is getting a partial screen grab.Like i say it works in release mode and i can just compile it in that. |
| ||
your image "scrshot" is to small for what you try to do. Probably you mean this: scrshot.WritePixels(pixels, 0, 0, SCREEN_WIDTH2, SCREEN_HEIGHT2) |
| ||
No because that would always grab the screen starting at position 0,0 .im trying to do a screen grab of a portion of the screen from any starting point I choose.the code works perfectly in release mode.what you suggest will work but will always start the grab at position 0,0.the only reason I have posted this as a bug is because I thought that things ran the same in debug or release mode.thanks for your suggestion though. |
| ||
that sounds strange for me... the ReadPixel() reads a screen rectangle from 100/100 to 300/300 and stores it in an array... The array is now filled from byte 0 to byte 40.000. With WritePixel you write back the content to a image. The parameters are now target coordinates! I think you want to fill the image starting at the left top corner... so x and Y now has to be 0/0! When you try to fill the image from 100/100 the 40.000 pixels will reach the coordinates 300/300, but the image width and height is only 200pixel. The only reason why it "works" in release mode, ist because the compiler gives no error messages in release mode. did you really test my suggestion? scrshot = CreateImage(SCREEN_WIDTH2, SCREEN_HEIGHT2) Local pixels:Int[] = New Int[SCREEN_WIDTH2 * SCREEN_HEIGHT2] ReadPixels(pixels, gs_x, gs_y, SCREEN_WIDTH2, SCREEN_HEIGHT2) scrshot.WritePixels(pixels, 0, 0, SCREEN_WIDTH2, SCREEN_HEIGHT2) |
| ||
I'm sure I tried that before I posted but I will try again tomorrow.im up at 530am so I've no time now.cheers for the help. |
| ||
ok just tested it and you are indeed correct.I really thought i tried that but obviously not.thanks for the explanation and bearing with me while i was being stupid. |