Código Delphi
[-]uses jpeg;
function jpgToGrayThumbnail(const FileName: string; Width: Integer): TBitmap;
var
jpg: TJPEGImage;
Color: PCardinal;
Count, y, x, Gray: Cardinal;
begin
jpg := TJPEGImage.Create;
jpg.LoadFromFile(FileName);
Result := TBitmap.Create;
Result.Width := Width;
with Result do
begin
Height := (Width * jpg.Height) div jpg.Width;
PixelFormat := pf32Bit;
Canvas.StretchDraw(Rect(0, 0, Width - 1, Height - 1), jpg);
Count := Abs(Cardinal(ScanLine[1]) - Cardinal(ScanLine[0])) div 4;
y := Height;
repeat Dec(y);
Color := ScanLine[y];
x := Count;
repeat Dec(x);
Gray := (GetRValue(Color^) + GetGValue(Color^) + GetBValue(Color^)) div 3;
Color^ := RGB(Gray, Gray, Gray);
Inc(Color);
until x = 0;
until y = 0;
end;
jpg.Free;
end;
modo de empleo:
Código Delphi
[-]procedure TForm1.Button1Click(Sender: TObject);
begin
Image1.Picture.Assign(jpgToGrayThumbnail('e:\Mis imágenes\0002.jpg', 80));
end;