delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback



Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi








Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


Get images (GIF/JPG) dimensionsFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi all versions
Category:
Graphic
Skill Level:
Scoring:
Last Update:
02/24/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet gif jpg dimensions width height
Times Scored:
2
Visits:
3313
Uploader: Khai Vuong Quang
Company:
Reference: N/A
 
Question/Problem/Abstract:
Get width and height of GIF/JPG images stored as arrays of bytes.
Optimized to use within server apps.
Answer:



function GetJpegSize(a: array of byte; var width, height: integer): boolean;
var
  i, n: integer;
begin
  n := length(a) - 8;
  i := 1;
  while (i < n) and (a[i] = $FF) do //Loop arround JPEG blocks
    case a[i + 1] of
      $C0 .. $C3: //Goal block
        begin
          height := a[i + 5] * 256 + a[i + 6];
          width := a[i + 7] * 256 + a[i + 8];
          Result := True;
          exit;
        end;
      $FF: //Nop block
        inc(i);
      $D0 .. $D9, $01: //Info block
        inc(i, 2);
      else //Normal block
        inc(i, a[i + 2] * 256 + a[i + 3] + 2);
    end;
  Result := False;
end;

function GetGifSize(a: array of byte; var width, height: integer): boolean;
begin
  Result := (a[1] = $47) and (a[2] = $49) and (a[3] = $46); //'GIF' Signature
  width := a[8] * 256 + a[7];
  height := a[10] * 256 + a[9];
end;


Functions return False if file is corrupted.

Usage:

var
  f: file;
  i, x, y: integer;
  a: array of byte;
begin
  assignfile(f, YOUR_GIF_FILENAME);
  reset(f, 1);
  i := filesize(f);
  setlength(a, i);
  blockread(f, a[1], i);
  if GetGIFSize(a, x, y) then
    writeln('Width ', x, ' Height ',y)
  else
    writeln('Error');
  closefile(f);
  readln;
end.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


   


  Community Ad of
E. DSpirito
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)