请问如何读取一幅JPEG图像的RGB值?(100分)

  • 主题发起人 主题发起人 |flybird532|+
  • 开始时间 开始时间
F

|flybird532|+

Unregistered / Unconfirmed
GUEST, unregistred user!
我使用的是TJEPGIMAGE类,图像已经读入
var
JpegImage1:TJPegImage;
Bitmap1:Tbitmap;
begin
jpegimage1:=TJpegimage.Create;
jpegimage1.LoadFromFile('hi.jpg');

////////////此处读取图像的RGB值并处理,请问如何做?

jpegimage1.Free;

end;
 
请问怎么转啊?
 
procedure TForm1.Button1Click(Sender: TObject);
var
jpeg: TJPEGImage;
bmp: TBitmap;
begin
if OpenPictureDialog1.Execute then
begin
jpeg := TJPEGImage.Create;
try
jpeg.LoadFromFile(OpenPictureDialog1.filename);
bmp := TBitmap.Create;
try
bmp.Assign(jpeg);
Image1.Picture.Graphic := bmp;
//此处读取图像的RGB值并处理
finally
bmp.free
end;
finally
jpeg.free
end;
end;
end;
 
谢谢linsb和影子,再请问得到bmp图像后怎么读取每个像素的RGB值呢,需要转换吗?
 
GetRValue
GetGValue
GetBValue
 
例子:
function ConvertBitmapToGrayscale1(const Bitmap: TBitmap): TBitmap;
var
i, j: Integer;
Grayshade, Red, Green, Blue: Byte;
PixelColor: Longint;
begin
with Bitmap do
for i := 0 to Width - 1 do
for j := 0 to Height - 1 do
begin
PixelColor := ColorToRGB(Canvas.Pixels[i, j]);
Red := PixelColor;
Green := PixelColor shr 8;
Blue := PixelColor shr 16;
Grayshade := Round(0.3 * Red + 0.6 * Green + 0.1 * Blue);
Canvas.Pixels[i, j] := RGB(Grayshade, Grayshade, Grayshade);
end;
Result := Bitmap;
end;

var
jpeg: TJPEGImage;
bmp: TBitmap;
begin
if OpenPictureDialog1.Execute then
begin
jpeg := TJPEGImage.Create;
try
jpeg.LoadFromFile(OpenPictureDialog1.filename);
bmp := TBitmap.Create;
try
bmp.Assign(jpeg);
//此处读取图像的RGB值并处理-图像的灰度处理
ConvertBitmapToGrayscale1(bmp);
Image1.Picture.Graphic := bmp;
finally
bmp.free
end;
finally
jpeg.free
end;
end;
end;

 
to linsb:
这段代码对小点的图片处理起来比较快,可对大点的图片进行灰度化比较慢了
能不能有个更好的办法?
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部