这样就拿到了(15,15)点的COLORREF值procedure TForm1.Button1Click(Sender: TObject); var dc: HDC; clr: COLORREF; begin dc := image1.Picture.Bitmap.Canvas.Handle; clr := GetPixel(dc, 15, 15); shape1.Brush.Color := clr; end;
再问一下: 一个bmp文件 我想读出它的没一个象素 其RGB值存到数组中
var bmparray:array[0..65534] of TColor; n,i,j:integer; begin Image.Picture.Bitmap.LoadFromFile('c:\Test.bmp'); n:=0; For i:=0 to Image.Picture.Bitmap.Width-1 do begin For j:=0 to Image.Picture.Bitmap.Height-1 do begin bmparray[n]:=Image.Picture.Bitmap.Canvas.Pixels[i,j]; Inc(n); end; end; end;
那可能是你自己犯了低级错误!这只是示例!比如: Image.Picture.Bitmap.LoadFromFile('c:\Test.bmp'); 上面是打开c:\Test.bmp,你的电脑不存在该文件!上面的方法比较容易,也可以用二维数组!其实Image.Picture.Bitmap.Canvas.Pixels[i,j]这就是二维,直接用不好吗?但从效率上说用ScanLine更好,比如:type TRGBArray = array[0..65534] of TRGBTriple; pRGBArray = ^TRGBArray; var n,i,j:Integer; rowIn:pRGBArray; begin Image.Picture.Bitmap.LoadFromFile('c:\Test.bmp'); n:=0; for j:=0 to Image.Picture.Bitmap.Height - 1 do begin rowIn:=Image.Picture.Bitmap.ScanLine[j]; for i := 0 to Image.Picture.Bitmap.Width - 1 do begin ... //获取RGB rowIn[i].rgbtRed,rowIn[i].rgbtGreen,rowIn[i].rgbtBlue; ... end; end; end;从TColor获得RGB信息: R := Color and $ff; G := Color and $ff00) shr 8; B := Color and $ff0000) shr 16;转16进制: IntToHex(R,2) IntToHex(G,2) IntToHex(B,2)
var
dc: HDC;
clr: COLORREF;
begin
dc := image1.Picture.Bitmap.Canvas.Handle;
clr := GetPixel(dc, 15, 15);
shape1.Brush.Color := clr;
end;
一个bmp文件 我想读出它的没一个象素 其RGB值存到数组中
bmparray:array[0..65534] of TColor;
n,i,j:integer;
begin
Image.Picture.Bitmap.LoadFromFile('c:\Test.bmp');
n:=0;
For i:=0 to Image.Picture.Bitmap.Width-1 do
begin
For j:=0 to Image.Picture.Bitmap.Height-1 do
begin
bmparray[n]:=Image.Picture.Bitmap.Canvas.Pixels[i,j];
Inc(n);
end;
end;
end;
Image.Picture.Bitmap.LoadFromFile('c:\Test.bmp');
上面是打开c:\Test.bmp,你的电脑不存在该文件!上面的方法比较容易,也可以用二维数组!其实Image.Picture.Bitmap.Canvas.Pixels[i,j]这就是二维,直接用不好吗?但从效率上说用ScanLine更好,比如:type
TRGBArray = array[0..65534] of TRGBTriple;
pRGBArray = ^TRGBArray;
var
n,i,j:Integer;
rowIn:pRGBArray;
begin
Image.Picture.Bitmap.LoadFromFile('c:\Test.bmp');
n:=0;
for j:=0 to Image.Picture.Bitmap.Height - 1 do
begin
rowIn:=Image.Picture.Bitmap.ScanLine[j];
for i := 0 to Image.Picture.Bitmap.Width - 1 do
begin
...
//获取RGB rowIn[i].rgbtRed,rowIn[i].rgbtGreen,rowIn[i].rgbtBlue;
...
end;
end;
end;从TColor获得RGB信息:
R := Color and $ff;
G := Color and $ff00) shr 8;
B := Color and $ff0000) shr 16;转16进制:
IntToHex(R,2)
IntToHex(G,2)
IntToHex(B,2)