Recent

Author Topic: Changing the color of one pixel in a image loaded into TImage.  (Read 9042 times)

T-bear

  • Full Member
  • ***
  • Posts: 160
Is it possible to change the color of one pixel in the picture that is loaded into a TImage?

Thanks! :D

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Changing the color of one pixel in a image loaded into TImage.
« Reply #1 on: April 05, 2011, 11:44:37 am »
Yes. Which pixel?

T-bear

  • Full Member
  • ***
  • Posts: 160
Re: Changing the color of one pixel in a image loaded into TImage.
« Reply #2 on: April 05, 2011, 11:45:34 am »
I dont know. Can i do that with coordinates or something?

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Changing the color of one pixel in a image loaded into TImage.
« Reply #3 on: April 05, 2011, 11:47:31 am »
Yes.

Code: [Select]
Image1.Canvas.Pixels[1,1] := clBlack;

T-bear

  • Full Member
  • ***
  • Posts: 160
Re: Changing the color of one pixel in a image loaded into TImage.
« Reply #4 on: April 05, 2011, 11:48:57 am »
Thanks

T-bear

  • Full Member
  • ***
  • Posts: 160
Re: Changing the color of one pixel in a image loaded into TImage.
« Reply #5 on: April 05, 2011, 06:08:53 pm »
And can I Change the color of every pixel in the picture to one color without doing that pixel by pixel

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Changing the color of one pixel in a image loaded into TImage.
« Reply #6 on: April 05, 2011, 07:37:33 pm »
Code: [Select]
Image1.Canvas.Brush.Color := clBlack;
Image1.Canvas.Pen.Color := clBlack;
Image1.Canvas.Rectangle(0,0, Image1.Width, Image1.Height); 

T-bear

  • Full Member
  • ***
  • Posts: 160
Re: Changing the color of one pixel in a image loaded into TImage.
« Reply #7 on: April 05, 2011, 07:46:45 pm »
Thanks!
Now i have just got a little problem.
When the form is created it makes all the TImages to blue. That works fine.
Code: [Select]
Buttons[Counter].Canvas.Brush.Color := clBlue;
Buttons[Counter].Canvas.Pen.Color := clBlue;
Buttons[Counter].Canvas.Rectangle(0,0, Buttons[Counter].Width, Buttons[Counter].Height);
But when i want to change the color when the image is clicked with this code
Code: [Select]
Buttons[H].Canvas.Brush.Color := BColor.ButtonColor;
Buttons[H].Canvas.Pen.Color := BColor.ButtonColor;
Buttons[H].Canvas.Rectangle(0,0, Buttons[H].Width, Buttons[H].Height);
it doesnt work, and i get exeption class External SIGSEGV. And the code where it is in the row
if not FUseParentCanvas and (FPicture.Graphic = nil) then
  begin
  //...
  end;
Whats going on now?

Thanks! :D

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Changing the color of one pixel in a image loaded into TImage.
« Reply #8 on: April 05, 2011, 07:52:55 pm »
Debug the code and find what line causes the error.

T-bear

  • Full Member
  • ***
  • Posts: 160
Re: Changing the color of one pixel in a image loaded into TImage.
« Reply #9 on: April 05, 2011, 08:00:54 pm »
if not FUseParentCanvas and (FPicture.Graphic = nil) then  // I think it's this. This line is highlighted when i press ok at the errormessage.
  begin
    //...
  end;

The File is CustomImage.Inc and in a comment at the beginning it says
"
This file is part of the Lazarus Component Library (LCL)                
    
 See the file COPYING.modifiedLGPL.txt, included in this distribution,    
 for details about the copyright.                                        
                                                                            
 This program is distributed in the hope that it will be useful,          
 but WITHOUT ANY WARRANTY; without even the implied warranty of          
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                    
 "                                                                          
 I think tits the unit for ExtCtrls or something...
« Last Edit: April 05, 2011, 08:02:50 pm by T-bear »

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Changing the color of one pixel in a image loaded into TImage.
« Reply #10 on: April 05, 2011, 08:24:52 pm »
The problem is not on that file, but in your code. Try to understand why the operation indicated there could not be made and change your code in order to make it possible.