TBitMap->Canvas->Pixels
__property TColor Pixels[int X][int Y] = {read=GetPixel, write=SetPixel};
enum TColor {clMin=-0x7fffffff-1, clMax=0x7fffffff};
0X00RRGGBB
RR R的值
GG G的值
BB B的值

解决方案 »

  1.   

    //Windows单元有一个RGB()函数;//看看我的例子
    //pas
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, ExtCtrls, ComCtrls;type
      TForm1 = class(TForm)
        TrackBar1: TTrackBar;
        TrackBar2: TTrackBar;
        TrackBar3: TTrackBar;
        Panel1: TPanel;
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        procedure FormCreate(Sender: TObject);
        procedure TrackBar1Change(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
    begin
      TrackBar1Change(TrackBar1);
    end;procedure TForm1.TrackBar1Change(Sender: TObject);
    begin
      Panel1.Color := RGB(TrackBar1.Position, TrackBar2.Position, TrackBar3.Position)
    end;end.//dfm
    object Form1: TForm1
      Left = 35
      Top = 121
      Width = 746
      Height = 205
      Caption = 'Form1'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      OnCreate = FormCreate
      PixelsPerInch = 96
      TextHeight = 13
      object Label1: TLabel
        Left = 168
        Top = 16
        Width = 8
        Height = 13
        Caption = 'R'
        FocusControl = TrackBar1
      end
      object Label2: TLabel
        Left = 168
        Top = 64
        Width = 8
        Height = 13
        Caption = 'G'
        FocusControl = TrackBar2
      end
      object Label3: TLabel
        Left = 168
        Top = 112
        Width = 7
        Height = 13
        Caption = 'B'
        FocusControl = TrackBar3
      end
      object TrackBar1: TTrackBar
        Left = 232
        Top = 8
        Width = 400
        Height = 45
        Max = 255
        Orientation = trHorizontal
        Frequency = 1
        Position = 0
        SelEnd = 0
        SelStart = 0
        TabOrder = 0
        TickMarks = tmBottomRight
        TickStyle = tsAuto
        OnChange = TrackBar1Change
      end
      object TrackBar2: TTrackBar
        Left = 232
        Top = 56
        Width = 400
        Height = 45
        Max = 255
        Orientation = trHorizontal
        Frequency = 1
        Position = 0
        SelEnd = 0
        SelStart = 0
        TabOrder = 1
        TickMarks = tmBottomRight
        TickStyle = tsAuto
        OnChange = TrackBar1Change
      end
      object TrackBar3: TTrackBar
        Left = 232
        Top = 104
        Width = 400
        Height = 45
        Max = 255
        Orientation = trHorizontal
        Frequency = 1
        Position = 0
        SelEnd = 0
        SelStart = 0
        TabOrder = 2
        TickMarks = tmBottomRight
        TickStyle = tsAuto
        OnChange = TrackBar1Change
      end
      object Panel1: TPanel
        Left = 40
        Top = 40
        Width = 89
        Height = 73
        Caption = 'Color'
        TabOrder = 3
      end
    end
      

  2.   

    用以下语句对每个象素点的R值降低100,为什么速度很慢,而且结果与photoshop转换的结果相
    差很远呀
     aColor:=Canvas.Pixels[x,y];
     canvas.Pixels[x,y]:=RGB((GetRValue(aColor)-$64),(GetGValue(aColor)),(GetBValue(aColor)));
      

  3.   

    为什么慢:
    应该在内存中操作一个canvas或者bitmap,然后一次性复制到屏幕上的canvas。慢就慢在每次对点赋值,就要刷新屏幕。
    为什么结果差很远:
    windows api rgb返回的颜色值,正好与delphi Tcanvas.Pixels的值在rgb的排列上是相反的。
      

  4.   

    可以用api函数:
    对每一个象素,用getpixel()取值,再用setpixel()赋值,但是速度慢
      

  5.   

    //我又来了
    //上次把你的问题弄错了
    //看看这次的吧//pas
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls, ExtCtrls, Buttons;type
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Image1: TImage;
        Button3: TButton;
        Image2: TImage;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
    begin
      Canvas.Draw(0, 0, Image2.Picture.Bitmap);
      Canvas.Draw(Image2.Width, Image2.Height, Image2.Picture.Bitmap);
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
      vCopyMode: TCopyMode;
    begin
      vCopyMode := Canvas.CopyMode;
      Canvas.CopyMode := cmSrcInvert;
      Image1.Canvas.Brush.Color := RGB($FF - $64, $00, $00);
      Image1.Picture.Bitmap.Width := Image2.Width;
      Image1.Picture.Bitmap.Height := Image2.Height;
      Image1.Canvas.FillRect(Rect(0, 0, Image2.Width, Image2.Height));
      Canvas.Draw(Image2.Width, Image2.Height, Image1.Picture.Bitmap);
      Canvas.CopyMode := vCopyMode;
    end;procedure TForm1.Button3Click(Sender: TObject);
    var
      I, J: Integer;
      aColor: TColor;
    begin
      for I := 1 to Image2.Width  do
        for J := 1 to Image2.Height do begin
          aColor := Canvas.Pixels[I, J];
          Canvas.Pixels[I, J] :=
            RGB((GetRValue(aColor) - $64),(GetGValue(aColor)),(GetBValue(aColor)));
        end;
    end;end.//dfm
    object Form1: TForm1
      Left = 192
      Top = 107
      Width = 490
      Height = 368
      Caption = 'Form1'
      Color = 15917024
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      PixelsPerInch = 96
      TextHeight = 13
      object Image1: TImage
        Left = 440
        Top = 0
        Width = 33
        Height = 33
      end
      object Image2: TImage
        Left = 336
        Top = 0
        Width = 32
        Height = 32
        AutoSize = True
        Picture.Data = {
          07544269746D6170BE000000424DBE000000000000003E000000280000002000
          000020000000010001000000000080000000130B0000130B0000020000000200
          000080000000FF0000000070003800F0003C00E01C1C01E0221E87C0410FFF80
          4107FF004103FC00220000001C000000000000FE000003018F80040070600800
          6010100090082000880820010804400104044001040440010404400104044000
          8408FC008408FF004413FF803867A7C00F8F11E0101E08E0201C04F0403C0371
          803800FE003800700038}
      end
      object Button1: TButton
        Left = 392
        Top = 224
        Width = 75
        Height = 25
        Caption = '复员'
        TabOrder = 0
        OnClick = Button1Click
      end
      object Button2: TButton
        Left = 392
        Top = 248
        Width = 75
        Height = 25
        Caption = '我的方法'
        TabOrder = 1
        OnClick = Button2Click
      end
      object Button3: TButton
        Left = 392
        Top = 272
        Width = 75
        Height = 25
        Caption = '你的方法'
        TabOrder = 2
        OnClick = Button3Click
      end
    end