Foxite.COM Community Weblog

Foxite.COM Community Weblog - free weblog service for the Visual FoxPro Community.
Welcome to Foxite.COM Community Weblog Sign in | Join | Help
in
Home Blogs Forum Photos Forum Archives

VFP IMAGING



GETTING IMAGE PROPERTIES WITH GDI+

LOCAL lcSource, lcInfo, lnWidth, lnHeight, lnHorRes, lnVerRes, lnPixForm
lcSource = GETPICT()

LOCAL loImage AS GpImage OF ffc/_gdiplus.vcx
loImage = NEWOBJECT("GpImage", HOME() + "ffc/_gdiplus.vcx")
loImage.CreateFromFile(lcSource)
 
lnWidth  = loImage.ImageWidth
lnHeight = loImage.ImageHeight
lnHorRes = loImage.HorizontalResolution
lnVerRes = loImage.VerticalResolution
lnPixForm = loImage.PixelFormat
lcPixForm = GetPixFormatName(lnPixForm)

lcInfo = "Image : " + lcSource + CHR(13) + CHR(13) +;
  "Width : " + TRANSFORM(lnWidth) + " pixels" + CHR(13) +;
  "Height : " + TRANSFORM(lnHeight) + " pixels" + CHR(13) +;
  "Pixel Format : " + lcPixForm + CHR(13) +;
  "Hor. Resol : " + TRANSFORM(lnHorRes) + " pixels/inch" + CHR(13) +;
  "Ver. Resol : "  + TRANSFORM(lnVerRes) + " pixels/inch" + CHR(13)

MESSAGEBOX(lcInfo, 64, "Image Information")
RETURN

PROCEDURE GetPixFormatName(nPix)
   DO CASE 
   CASE
nPix = 0x00030101
      RETURN "1bppIndexed"
   CASE nPix = 0x00030402
      RETURN "4bppIndexed"
   CASE nPix = 0x00030803
      RETURN "8bppIndexed"
   CASE nPix = 0x00101004
      RETURN "16bppGrayScale"
   CASE nPix = 0x00021005
      RETURN "16bppRGB555"
   CASE nPix = 0x00021006
      RETURN "16bppRGB565"
   CASE nPix = 0x00061007
      RETURN "16bppARGB1555"
   CASE nPix = 0x00021808
      RETURN "24bppRGB"
   CASE nPix = 0x00022009
      RETURN "32bppRGB"
   CASE nPix = 0x0026200A
      RETURN "32bppARGB"
   CASE nPix = 0x000E200B
      RETURN "32bppPARGB"
   CASE nPix = 0x0010300C
      RETURN "48bppRGB"
   CASE nPix = 0x001C400E
      RETURN "64bppPARGB"
   OTHERWISE
      RETURN "Unidentified"
   ENDCASE
ENDPROC

Published Wednesday, March 01, 2006 3:39 AM by cesarchalom
Filed Under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

ChrisRChamberlain said:

Cesar

Excellent as ever - small typo in code

"Height : " + TRANSFORM(lnWidth)

should be

"Height : " + TRANSFORM(lnHeight)

Hi Chris,

Thanks for reporting ! I've already updated the text.

Regards,

Cesar

July 11, 2007 1:42 PM
 

Lucian Ilea said:

Thanks for this code. It is very usefull. Ca you get more information from an image file this way (camera to take the picture, lens aperture, etc.)?

Thank you!

Of course it is possible !

We have a great sample in the GdiPlusX samples. Please download the samples project from GdiPlusX, and run the sample "ImageProps.Scx", or directly from the samples menu select "Image Properties". It uses the function "GetPropertyItem" to retrieve the metadata embedded in the picture file. Try the sample, selecting some digital pictures that you took with your camera, and you'll find some really cool info.

Hope this helps !

May 9, 2008 1:55 PM

What do you think?

(required) 
(optional)
(required)