2006-03-01

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


2 comments:

  1. ChrisRChamberlainJuly 11, 2007 at 10:42 AM

    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

    ReplyDelete
  2. 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 !

    ReplyDelete