Link to home
Start Free TrialLog in
Avatar of cc_2000_sg
cc_2000_sg

asked on

hi, can you help me, urgent!!!!!

hi all,

my project requires me to use open dialog to get some image files, eg .gif. but can i get the size of that image?


best regards

cc_2000_sg
Avatar of cc_2000_sg
cc_2000_sg

ASKER

in pixel.
You really aren't supposed to be asking folks to do your homework for you... aside from being against EE's policy, you are never going to learn this stuff if you have someone do it for you all the time.If you have  an inkling of how to go about it and need some confirmation or a pointer in the right direction, then I personally would be happy to help you out, but I won't do your homework.


Good luck!!
Hi cc,

Using a TOpenPictureDialg will not only give you the ability to preview the image before loading it, but it will also give you the size (height x width).  However, it only work with BMP, WMF, ICO, BMP and JPGs.  If you want to be able to use more image types, you'll have to get yourself some new components which support other file formats.

If you want the info once you've loaded the image, you can just get the height and width of the image's canvas.

Hope this helps,

Stu
Well, that's a fantastic contribution!  Well done, Spaz!
ASKER CERTIFIED SOLUTION
Avatar of GaryBond
GaryBond

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SPastIC_NolA
Comments Deleted, Account Deleted

kb
Community Support Moderator
Experts Exchange
sorry,

i think this is my fault. i didn't say clearly that

what i want is getting the width and height of the image

instead of how many byte of the image.

can you those experts give me more suggestions?


cc_2000_sg
You wont be able to get these details until you've opened the file.  To do this, use this code:

type
  TImageInfo = record
    Width: Integer;
    Height: Integer;
    Filename: String;
    Valid: Boolean;
  end;

procedure GetBMPInfo(ImageFilename: String): TImageInfo;
var
 BMP: TBitmap;

begin
  BMP := TBitmap.Creatae;
  try
    if not FileExists(Filename) then
      begin
        Showmessage('File not found')
        Result.Valid := false;
        Exit;
      end;

      BMP.LoadFromFile(Filename);
      Result.Width := BMP.Width;
      Result.Height := BMP.Height;
      Result.Filename := ImageFilename;
      Result.Valid := true;
    Resul
  finally
    BMP.Free;
  end;
end;

procedure ShowOpenDialog;
begin
  with TOpenDialog.Create(nil) do
    try
      Filter := 'Bitmaps|*.BMP';
      IndexIndex := 0;
      Title := 'Open BMP';
      InitialDir := ExtractFilePath(Application.ExeName);
      if Execute then
        GetBMPInfo(Filename);
    finally
      free; {TOpenDialog}
    end;
end;

As mentioned previously, to work with other file types (GIF, PSP, TIF etc), you'll need extra source.  The code above can be easily modified to work with ICO, JPG and WMF files (which are all natively supported by Delphi).

I hope this helps,

Stu
Basically, there is no "easy way" of getting information about a GIF file built into Delphi.  As mentioned you would need to either get some additional components or write some code to read GIF headers.

I vaguely remember having such code on my hard drive somewhere, but then again my HD has several GB of sources, components, libraries, etc.  Or maybe I saw it in one of my books.  Don't remember, unfortunately.  And, I'm sorry, but it would take way too long to find for the points.

If you also need to read in (display/process/whatever) the GIF image then you definately need some components/library to handle GIF images.  If you only need to extract information about the GIF files (such as size) then you could probably find some much simplier code to do just that.

Wish I could have been more help.

James Higgins
Delphi Architect
cc_2000_sg:

You have many open questions:

https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20244798
https://www.experts-exchange.com/jsp/qShow.jsp?ta=java&qid=20207015
https://www.experts-exchange.com/jsp/qShow.jsp?ta=visualbasic&qid=20265037
https://www.experts-exchange.com/jsp/qShow.jsp?ta=xml&qid=20168208
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20245899
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20253932
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20257549
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20258338
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20258362
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20263682
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=20263684
https://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=20246240

To assist you in your cleanup, I'm providing the following guidelines:

1.  Stay active in your questions and provide feedback whenever possible. Likewise, when feedback has not been provided by the experts, commenting again makes them receive an email notification, and they may provide you with further information. Experts have no other method of searching for questions in which they have commented, except manually.

2.  Award points by hitting the Accept Comment As Answer button located above and to the left of that expert's comment.

3.  When grading, be sure to read:
https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp#3
to ensure that you understand the grading system here at EE. If you grade less than an A, you must explain why.

4.  Questions that were not helpful to you should be PAQ'd (stored in the database for their valuable content?even if not valuable to you) or deleted. To PAQ or delete a question, you must first post your intent in that question to make the experts aware. Then, if no experts object after three full days, you can post a zero-point question at community support to request deletion or PAQ. Please include the link(s) to the question(s).
CS:  https://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
At that point, a moderator can refund your points and PAQ or delete the question for you. The delete button does not work.

5.  If you fail to respond to this cleanup request, I must report you to the Community Support Administrator for further action.

Our intent is to get the questions cleaned up, and not to embarrass or shame anyone. If you have any questions or need further assistance at all, feel free to ask me in this question or post a zero-point question at CS. We are very happy to help you in this task!


thanks!
amp
community support moderator

cc_2000_sg,

I'm a little curious here.  How come you awarded GaryBond the points when you quite clearly stated that you didn't want the file size? You said "what i want is getting the width and height of the image instead of how many byte of the image."  The code I supplied will return the width and height of the image.

Can you please explain your reasons for this?

Stu.