whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

90 Visitors Online


 
...get/set JPG resolution?
Autor: Marcio Ehrlich
[ Print tip ]  

Tip Rating (24):  
     


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;

 

Rate this tip:

poor
very good


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