delphi 獲取圖片某一像素的顏色值

前言:在VCL裏有GetPixel函數,可直接用,在FMX裏直接用這個函數沒有定義,在FMX的library中找這個函數在FMX.Graphics.TBitmapData.GetPixel中html

  結果我引用FMX.Graphics不行,引用FMX.Graphics.TBitmapData也不行,而後我就鬱悶了半天。函數

  後來我聲明瞭一個TBitmapData變量,結果能夠使用該函數了,我欣喜若狂...orm

在窗體上放一個Image,在Image的OnMouseUp事件中取出鼠標點擊那點的像素htm

procedure TForm2.Image1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
var
	vBitMapData: TBitmapData;
	color: TAlphaColor;
begin
	if Image1.Bitmap.Map(TMapAccess.Write, vBitMapData) then 
	begin
		color := vBitMapData.GetPixel(Round(X), Round(Y));  // 獲取像素 返回類型爲TAlphaColor
		ShowMessage(IntToHex(color, 1));              //爲十六進制的顏色值
	end;
	Image1.Bitmap.Unmap(vBitMapData);
end;

http://www.cnblogs.com/studypanp/p/5003036.html 獲取RGBblog

相關文章
相關標籤/搜索