Ver Mensaje Individual
  #6  
Antiguo 10-03-2008
Avatar de cHackAll
[cHackAll] cHackAll is offline
Baneado?
 
Registrado: oct 2006
Posts: 2.159
Reputación: 22
cHackAll Va por buen camino
No es por competir, pero la verdad que me daba mucha pena echar mi código al basurero;

Código Delphi [-]
function GetDimensions(lpFileName: PChar): TSize;
var hFile: Integer; Value, FileSize: Cardinal; Chunk: Word;
begin
 Result := TSize(Point(0, 0));
 hFile := _lopen(lpFileName, OF_READ);
 if hFile = -1 then Exit;
 _lread(hFile, @Value, 4);
 if Word(Value) = $4D42{BM} then
  begin
   _llseek(hFile, 18, FILE_BEGIN);
   _lread(hFile, @Result, SizeOf(Result));
  end
 else
  begin
   if Value = $E0FFD8FF{JPEG} then
    begin
     _lread(hFile, @Chunk, 2);
     _lread(hFile, @Value, 4);
     if Value = $4649464A{JFIF} then
      begin
       FileSize := GetFileSize(hFile, nil);
       Value := 4 + Swap(Chunk);
       while Value < FileSize do
        begin
         _llseek(hFile, Value, FILE_BEGIN);
         Inc(Value, 2); _lread(hFile, @Chunk, 2);
         if Lo(Chunk) <> $FF then Exit;
         if Hi(Chunk) = $C0 then
          begin
           _llseek(hFile, Value + 3, FILE_BEGIN);
           _lread(hFile, @Chunk, 2); Result.cy := Swap(Chunk);
           _lread(hFile, @Chunk, 2); Result.cx := Swap(Chunk);
           Break;
          end
         else
          begin
           _lread(hFile, @Chunk, 4);
           Inc(Value, Swap(Chunk));
          end;
        end;
      end;
    end;
  end;
 CloseHandle(hFile);
end;

Uso;

Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
var Size: TSize;
begin
 if OpenDialog1.Execute then
  begin
   Size := GetDimensions(PChar(OpenDialog1.FileName));
   ShowMessage(IntToStr(Size.cx) + 'x' + IntToStr(Size.cy));
  end;
end;

PD: Nadamas por curiosidad, cual es la velocidad de mi code?

Saludos
Responder Con Cita