2007-04-08

Image Info with GdiPlus X

another very easy task for gdi+.


to obtain some basic image information, such as width, height, resolution and pixelformat, all we need is to initialize a gdi+ image object and get some property values, as shown below:


important:


all samples below use the new gdiplus-x library, that is still in alpha version, but is already stable and reliable to do the majority of gdi+ tasks. download the latest stable release from codeplex:

http://www.codeplex.com/wiki/view.aspx?projectname=vfpx&title=gdiplusx



local lcimage
lcimage =
getpict()
if empty(lcimage)
   return
endif


do locfile("system.app")


local loimg as xfcimage
with _screen.system.drawing
loimg = .
image.fromfile(lcimage)
if isnull(loimg)
   messagebox("could not load image file")
   return
endif


* get pixelformat name
local lnpix, lcpixformat
lnpix = loimg.pixelformat
do case 
case
lnpix = .imaging.pixelformat.format1bppindexed
   lcpixformat = "1bppindexed"
case lnpix = .imaging.pixelformat.format4bppindexed
   lcpixformat = "4bppindexed"
case lnpix = .imaging.pixelformat.format8bppindexed
   lcpixformat = "8bppindexed"
case lnpix = .imaging.pixelformat.format16bppgrayscale
   lcpixformat = "16bppgrayscale"
case lnpix = .imaging.pixelformat.format16bpprgb555
   lcpixformat = "16bpprgb555"
case lnpix = .imaging.pixelformat.format16bpprgb565
   lcpixformat = "16bpprgb565"
case lnpix = .imaging.pixelformat.format16bppargb1555
   lcpixformat = "16bppargb1555"
case lnpix = .imaging.pixelformat.format24bpprgb
   lcpixformat = "24bpprgb"
case lnpix = .imaging.pixelformat.format32bpprgb
   lcpixformat = "32bpprgb"
case lnpix = .imaging.pixelformat.format32bppargb
   lcpixformat = "32bppargb"
case lnpix = .imaging.pixelformat.format32bpppargb
   lcpixformat = "32bpppargb"
case lnpix = .imaging.pixelformat.format48bpprgb
   lcpixformat = "48bpprgb"
case lnpix = .imaging.pixelformat.format64bpppargb
   lcpixformat = "64bpppargb"
otherwise
   lcpixformat = "unidentified"
endcase


endwith
 
local
lcinfo
lcinfo = ;
   "width : " +
transform(loimg.width) + space(25) +;
   "height : " +
transform(loimg.height) + chr(13) +;
   "resolution - vertical : " +
transform(loimg.verticalresolution) +  space(6) +;
   "horizontal : " +
transform(loimg.horizontalresolution) + chr(13) +;
   "pixelformat : " + lcpixformat


messagebox(lcinfo, 64, "image properties for " + justfname(lcimage))

3 comments:

  1. Felicitaciones Cesar, muy bueno tu apoyo a la comunidad.

    Saludos.
    Gracias Franklin!
    Esta es una hora en que debemos nos unir y crear nuevas opciones, y muestrar que con VFP todo se puede hacer. Para eso, solo se necesita un poco de creatividad !
    Saludos
    Cesar

    ReplyDelete
  2. Franklin,

    Mas un dato interesante:

    UD paso hace un mes un link para la clase de objectos degradados en FoxEcuador. Hubieron mas de 100 acesos a este articulo desde FoxEcuador ! Esto fue la origen que mas acesos tuve !

    ReplyDelete
  3. Versión en Español de este artículo en / Spanish version at  http://www.portalfox.com/article.php?sid=2405

    ReplyDelete