Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Crear Thumbnails en blanco y negro de archivos JPEG (https://www.clubdelphi.com/foros/showthread.php?t=80830)

cHackAll 12-08-2007 01:44:40

Crear Thumbnails en blanco y negro de archivos JPEG
 
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;
//   SaveToFile('cache.bmp'); // Opcional 
  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;


La franja horaria es GMT +2. Ahora son las 11:07:45.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi