Solved

How do I retrieve and display image properties in Delphi7?

Posted on 2007-11-23
11
449 Views
Last Modified: 2013-11-23
I am working on a simple image viewer in Delphi that loads an image then displays the image properties (eg date created, file size etc) I'm ok with loading the image, but how do I display the image properties in a label?
0
Comment
Question by:gedge73
  • 6
  • 3
  • 2
11 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 20339935
this is called 'exif data' and can be read from jpegs using this opensource library: http://mcguirez.homestead.com/downloads.html
0
 

Author Comment

by:gedge73
ID: 20339943
HI, thanks for the quick response, but it's bmp files I'm working with
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20339956
ok, but bmp's do not have exif data.

What kind of information do you mean?
0
 

Author Comment

by:gedge73
ID: 20339974
I need to display

File SIze
Dimensions
Date Created

from the bmp that is currenlty loaded
0
 
LVL 28

Expert Comment

by:2266180
ID: 20339986
the "etc" part is pretty important.

for file details, you can do something like this:

var r:tsearchrec;
if findfirst(filename, faanyfile, r)=0 then
begin
  r contains file info (created date, last accessed date, file size, etc)
so just display them in your label/memo/whatever
end;

if you need more info, like iptc or exif for jpg, or otehr information that are in the image and format dependent, you need some library/component that can do that.

for non image format dependent data, you can just load the image in a timage and egt the info from there:
- width, height, bitsperpixel, etc.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:gedge73
ID: 20340045
Sorry man, I'm new at this Delphi.

 I am loading the image into a Timage, does that make it easier to display the properties?
0
 
LVL 28

Accepted Solution

by:
2266180 earned 500 total points
ID: 20340126
well, isn't that what I said to do in order to display the image related info? (heith/width/bits per pixel/etc).
but for file size, created date, etc, you need the other thing with the findfirst (which will require a findclose after it, forgot to mention).

and just because you're new at delphi, doesn't mean that you have to be lazy, does it?

ctrl+f1 on a function name will get the help on that function.
write a record or object type followed by fot (.) and right after press ctrl+space
this will show you all the functions/procedures/members that can be accessed from that record/object.

you cannot expect us to give you code when you don't even say what exactly you want to do. you want to display in a label. one label? more lables? exactly what information? etc is not helping, is it, since right now we have 2 palces to get the info from and if you need some other info, there might be a need for a 3rd place.

attached is a small demo to get some of the info. I thin you can manage to get the rest and make them showup on lables or memo or whatever you actually want.
unit Unit1;
 

interface
 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, ExtCtrls;
 

type

  TForm1 = class(TForm)

    Image1: TImage;

    procedure FormCreate(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

  end;
 

var

  Form1: TForm1;
 

implementation
 

{$R *.dfm}
 

function FileTime2DateTime

   (FileTime: TFileTime): TDateTime;

var

   LocalFileTime: TFileTime;

   SystemTime: TSystemTime;

begin

   FileTimeToLocalFileTime(FileTime, LocalFileTime) ;

   FileTimeToSystemTime(LocalFileTime, SystemTime) ;

   Result := SystemTimeToDateTime(SystemTime) ;

end;
 

procedure TForm1.FormCreate(Sender: TObject);

var r:tsearchrec;

    i:timage;

    bpp:string;

begin

  if findfirst('c:\test.bmp', faanyfile, r)=0 then

  try

    showmessage('file created on: '+datetimetostr(FileTime2DateTime(r.FindData.ftCreationTime)));

    showmessage('file size is: '+inttostr(int64(r.FindData.nFileSizeHigh shl 32+r.FindData.nFileSizeLow))+' bytes');

  finally

    findclose(r);

  end;

  i:=timage.Create(nil);

  try

    i.Picture.LoadFromFile('c:\test.bmp');

    showmessage('image width: '+inttostr(i.Picture.Width));

    showmessage('image height: '+inttostr(i.Picture.Height));

    case i.Picture.Bitmap.PixelFormat of

      pfDevice:bpp:='device dependent';

      pf1bit:bpp:='1 bit';

      pf4bit:bpp:='4 bit';

      pf8bit:bpp:='8 bit';

      pf15bit:bpp:='15 bit';

      pf16bit:bpp:='16 bit';

      pf24bit:bpp:='24 bit';

      pf32bit:bpp:='32 bit';

      pfCustom:bpp:='custom';

    end;

    showmessage('image bitsperpixel: '+bpp);

  finally

    freeandnil(i);

  end;

end;
 

end.

Open in new window

0
 

Author Comment

by:gedge73
ID: 20340181
Ok thanks for the advice, but I think you're a bit cheeky.
Remember I did say I was a beginner on this subject. I wasn't being lazy just needed a few pointers.
Your manner could perhaps be addressed or it might put some people off.
0
 

Author Closing Comment

by:gedge73
ID: 31410678
Thanks again, it is appreciated
0
 

Author Comment

by:gedge73
ID: 20340235
Thanks, that works a treat.
0
 
LVL 28

Expert Comment

by:2266180
ID: 20340344
and you gave me a B grade because you had the impression that I was cheeky? (which I don't know what it means and you jsut took away my desire to find out)

ok. have it your way. you punish me with a B grade, I punish you with something that hurts you more than your B grade hurts me.

Here is how things *should work* on EE:

Any expert MUST have the chance to earn an A grade. Just because there is a slight change needed in order to make the code work, which is not even the experts fault since you are the one that did not give sufficient information or asked for clarifications, that is not a reason to give a B grade. The manner in which the expert give the answer is again not a reason for a B grade. Just because you feel that I was cheeky, or whatever, that is your own problem. This is written communication. No smilies, no text formatiing, no nothing. Simple, clean text. I have my own way of expressing myself, and maybe sometimes I don't choose the correct words, but that is because my english is not perfect.

Either award the expert an A grade or just tell him the problem and let him solve/explain it so he can earn it. But cutting the problem down and not allowing the expert to earn the A grade is very frustrating for the expert.

Hence, you are the 4th person to make it on my blacklist. Which basically means that from now on and forever I will ignore your every question.
If you treat other experts like this, that follow a similar policy as myself, you will soon find yourself with little or no experts to answer your questions.

This is just a notice. No need to reply as I unsubscribed from this question.

Enjoy.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi with SQL Natvie Client 15 86
delphi exception 7 61
Delphi XE10, MySQL Query 4 126
HTML text in the body of an email (delphi code) 12 95
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now