Pset(Pictureなど)


Psetメソッドは指定された座標一ピクセルを着色します。Delphiでは TCanvas型のプロパティを持っているコンポーネントなら TCanvasの「Pixels」プロパティを使用して設定できます。

■ TImageにロードした画像の色を反転する例
  procedure TForm1.Button1Click(Sender: TObject);
  var
    x,y : integer;
    colPix  : TColor;
    intPix  : LongInt;
  begin
    {画像を開くダイアログ}
    if  (OpenPictureDialog1.Execute)  then  begin
      {画像を読み込む}
      Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
      {画像にコントロールのサイズを合わせる}
      Image1.AutoSize :=  True;
      for y :=  0 to  Image1.Height do  begin
        for x :=  0 to  Image1.Width  do  begin
          {色取得}
          colPix  :=    Image1.Canvas.Pixels[x,y];
          intPix  :=    ColorToRGB(colPix);
          {色設定}
          Image1.Canvas.Pixels[x,y] :=  Abs((255 * 255 * 255) - intPix);
        end;
      end;
    end;
  end;