was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1547)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (115)
IDE (21)
Indy (5)
Internet / LAN (131)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (127)
Strings (83)
System (268)
VCL (243)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

34 Visitors Online


 
...die Auflösung eines JPG Bilder ermitteln/setzen?
Autor: Marcio Ehrlich
[ Tip ausdrucken ]  

Tip Bewertung (23):  
     


procedure GetResJpg(JPGFile: string);
const
  
BufferSize = 50;
var
  
Buffer: string;
  Index: integer;
  FileStream: TFileStream;
  HorzRes, VertRes: Word;
  DP: Byte;
  Measure: string;
begin
  
FileStream := TFileStream.Create(JPGFile,
    fmOpenReadWrite);
  try
    
SetLength(Buffer, BufferSize);
    FileStream.Read(buffer[1], BufferSize);
    Index := Pos('JFIF' + #$00, buffer);
    if Index > 0 then
    begin
      
FileStream.Seek(Index + 6, soFromBeginning);
      FileStream.Read(DP, 1);
      case DP of
        
1: Measure := 'DPI'; //Dots Per Inch
        
2: Measure := 'DPC'; //Dots Per Cm.
      
end;
      FileStream.Read(HorzRes, 2); // x axis
      
HorzRes := Swap(HorzRes);
      FileStream.Read(VertRes, 2); // y axis
      
VertRes := Swap(VertRes);
    end
  finally
    
FileStream.Free;
  end;
end;

procedure SetResJpg(name: string; dpix, dpiy: Integer);
const
  
BufferSize = 50;
  DPI = 1; //inch
  
DPC = 2; //cm
var
  
Buffer: string;
  index: INTEGER;
  FileStream: TFileStream;
  xResolution: WORD;
  yResolution: WORD;
  _type: Byte;
begin
  
FileStream := TFileStream.Create(name,
    fmOpenReadWrite);
  try
    
SetLength(Buffer, BufferSize);
    FileStream.Read(buffer[1], BufferSize);
    index := POS('JFIF' + #$00, buffer);
    if index > 0
      then begin
      
FileStream.Seek(index + 6, soFromBeginning);
      _type := DPI;
      FileStream.write(_type, 1);
      xresolution := swap(dpix);
      FileStream.write(xresolution, 2);
      yresolution := swap(dpiy);
      FileStream.write(yresolution, 2);
    end
  finally
    
FileStream.Free;
  end;
end;

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners