Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
- type
- TForm1 = class(TForm)
- Memo1: TMemo;
- Button1: TButton;
- Button2: TButton;
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- private
- { Private 宣言 }
- procedure OutputRGB(Col: TColor);
- public
- { Public 宣言 }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- uses
- Jpeg;
- procedure TForm1.OutputRGB(Col: TColor);
- type
- TRGB = packed record
- case Integer of
- 0: (Col: TColor;);
- 1: (R: Byte;
- G: Byte;
- B: Byte;
- I: Byte;);
- end;
- var
- RGB: TRGB;
- R, G, B: Byte;
- begin
- // レコード型を使った、TColor値 → R,G,Bの取り出し
- RGB.Col:=Col;
- Memo1.Lines.Add(Format('BGR=$%.8x',[RGB.Col]));
- Memo1.Lines.Add(Format('R=$%.2x, G=$%.2x, B=$%.2x',[RGB.R, RGB.G, RGB.B]));
- // 関数(マクロ扱い)を使った、TColor値 → R,G,Bの取り出し
- R:=GetRValue(Col);
- G:=GetGValue(Col);
- B:=GetBValue(Col);
- Memo1.Lines.Add(Format('R=$%.2x, G=$%.2x, B=$%.2x',[R, G, B]));
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- const
- // Bmpファイルを指定する
- BMPFile='C:\~\Test.bmp';
- var
- BMP: TBitmap;
- begin
- BMP:=TBitmap.Create;
- try
- BMP.LoadFromFile(BMPFile);
- Memo1.Lines.Add('----------'+ExtractFileName(BMPFile));
- OutputRGB(BMP.Canvas.Pixels[100, 100]);
- finally
- BMP.Free;
- end;
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- const
- // Jpegファイルを指定する
- JPGFile='C:\~\Test.jpg';
- var
- JPG: TJPEGImage;
- BMP: TBitmap;
- begin
- JPG:=TJPEGImage.Create;
- BMP:=TBitmap.Create;
- try
- JPG.LoadFromFile(JPGFile);
- BMP.Assign(JPG);
- Memo1.Lines.Add('----------'+ExtractFileName(JPGFile));
- OutputRGB(BMP.Canvas.Pixels[100, 100]);
- finally
- BMP.Free;
- JPG.Free;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement