Ver Mensaje Individual
  #1  
Antiguo 12-08-2007
Avatar de cHackAll
[cHackAll] cHackAll is offline
Baneado?
 
Registrado: oct 2006
Posts: 2.159
Reputación: 20
cHackAll Va por buen camino
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;
Responder Con Cita