掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
BMP画像から線を読み取るには? (ID:2585)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
こんにちは。はじめまして。 VBでいう、PSET関数、PGET関数を作ってみました。 ScanLineをじかに使うよりはかなり遅いですが、Pixelsをつかうよりは かなり早いです。 procedure pset(bmp:TBitmap;point:TPoint;R,G,B:byte); Type TRGB=record B,G,R:byte; end; TRGBArray=array[0..65535] of TRGB; PRGBArray=^TRGBArray; var Color:TRGB; Line:PRGBArray; begin if (bmp.Width<=0) or (bmp.Height<=0) then exit; if (point.x<0) or (point.x>(bmp.Width -1)) or (point.y<0) or (point.y>(bmp.height-1)) then exit; if Bmp.PixelFormat<>pf24bit then Bmp.PixelFormat:=pf24bit; Line:=Bmp.ScanLine[point.y]; Color:=Line^[point.x]; Color.R:=Byte(r); Color.G:=Byte(g); Color.B:=Byte(b); Line^[point.x]:=Color; end; procedure pget(bmp:TBitmap;point:TPoint;var R,G,B:byte); Type TRGB=record B,G,R:byte; end; TRGBArray=array[0..65535] of TRGB; PRGBArray=^TRGBArray; var Color:TRGB; Line:PRGBArray; begin if (bmp.Width<=0) or (bmp.Height<=0) then exit; if (point.x<0) or (point.x>(bmp.Width -1)) or (point.y<0) or (point.y>(bmp.height-1)) then exit; if Bmp.PixelFormat<>pf24bit then Bmp.PixelFormat:=pf24bit; Line:=Bmp.ScanLine[point.y]; Color:=Line^[point.x]; r:=Color.R; g:=Color.G; b:=Color.B; end; 使い方の例: procedure TForm1.Button1Click(Sender: TObject); var x,y:integer; point:TPoint; begin Image1.Canvas.FillRect(rect(0,0,Image1.Width-1,Image1.Height-1)); for x:=0 to Image1.Width-1 do for y:=0 to Image1.Height-1 do begin point.X:=x; point.Y:=y; Pset(Image1.Picture.Bitmap,point,255,0,0); end; Image1.Refresh; end; procedure TForm1.Button2Click(Sender: TObject); var point:TPoint; r,g,b:byte; begin point.X:=0; point.Y:=0; pget(Image1.picture.Bitmap,point,r,g,b); showmessage('R='+inttostr(r)+' G='+inttostr(g)+' B='+inttostr(b)); end;
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.