Recent

Author Topic: Analysing pixel values returns -1  (Read 2641 times)

Pi

  • Jr. Member
  • **
  • Posts: 61
Analysing pixel values returns -1
« on: August 05, 2014, 10:07:10 pm »
In a program where I'm setting a variable to the pixel value at a particular position, it returns a proper result if the form and image is showing on my desktop, but if I click on something else so that the form from the program isn't showing on my desktop, the pixel vaue returns -1. How can I get it to always return the proper result, even if I minimize the form or click on something else so the program's form isn't showing.

eg.   pixel1_val:=image1.canvas.pixels[x1+x_count,y1+y_count];   

pixel1_val gets set to -1 if the form is minimised.
Lazarus version 0.9.30.4 + Lazarus 32 bit 1.2.6

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Analysing pixel values returns -1
« Reply #1 on: August 05, 2014, 11:21:50 pm »
You can check from image1.picture.bitmap.canvas. That is buffer that is permanent, but anything you draw on image1.canvas will not show on ...bitmap.canvas. You can draw on that though.

Pi

  • Jr. Member
  • **
  • Posts: 61
Re: Analysing pixel values returns -1
« Reply #2 on: August 05, 2014, 11:47:33 pm »
You can check from image1.picture.bitmap.canvas. That is buffer that is permanent, but anything you draw on image1.canvas will not show on ...bitmap.canvas. You can draw on that though.
Thanks, but isn't that not taking into account any changes in image size. eg. if I resize an image, by just changing eg. image1.width I then want to be able to check the pixel values of the resized image, but if I check image1.picture.bitmap.canvas, won't that be using the original (not resized) image?
Lazarus version 0.9.30.4 + Lazarus 32 bit 1.2.6

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Analysing pixel values returns -1
« Reply #3 on: August 06, 2014, 02:30:30 am »
You could have an internal copy of the bitmap on you app for this.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7497
Re: Analysing pixel values returns -1
« Reply #4 on: August 06, 2014, 08:34:35 am »
You can check from image1.picture.bitmap.canvas. That is buffer that is permanent, but anything you draw on image1.canvas will not show on ...bitmap.canvas. You can draw on that though.
Thanks, but isn't that not taking into account any changes in image size. eg. if I resize an image, by just changing eg. image1.width I then want to be able to check the pixel values of the resized image, but if I check image1.picture.bitmap.canvas, won't that be using the original (not resized) image?

True, but it will only adapt to size when actually painted anyway.

Pi

  • Jr. Member
  • **
  • Posts: 61
Re: Analysing pixel values returns -1
« Reply #5 on: August 06, 2014, 05:19:51 pm »
Thanks for the replies typo and marcov. I wanted the easiest way to be able to check the pixel values (as well as hopefully be fast) of the resized image (the pixel values after resizing), that also wasn't affected by things like minimizing the form (since my other method had been affected by that).

I think the suggestion of using 'an internal copy of the bitmap' seems like it it's what I would be best using thanks, so I'll try doing that instead of checking the pixel values of the images on the form. And I'll use stretchdraw on the internal bitmap for the resizing.

Thanks.
« Last Edit: August 06, 2014, 05:22:48 pm by Pi »
Lazarus version 0.9.30.4 + Lazarus 32 bit 1.2.6