Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to create thumbnails of 96x96 with GDI+ ?
Message
From
16/08/2006 05:29:11
 
 
To
14/08/2006 07:55:03
Dorin Vasilescu
ALL Trans Romania
Arad, Romania
General information
Forum:
Visual FoxPro
Category:
Pictures and Image processing
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01145222
Message ID:
01145914
Views:
33
>>Hello,
>>
>>I would like to have thumbnails from JPG images.
>>Like in Windows explorer, I want to have thumbnails of 96x96 pixel.
>>If the image is in portrait, there will be space on the right and left side and if it's in landscape, there will be space on the top and the bottom.
>>
>>My idea was to use gdiplus like this :
>>- create a blank image of 96x96 (OK)
>>- resize the image to fit in the blank one (OK)
>>- Paste the resized image in the blank one (Can't find how...)
>>
>>In gdiplus, I can't find how to paste an image into another...
>>
>>Any tips ?
>>
>>Thanks,
>>Regards
>>Steph
>
>
>PROCEDURE ResizeImage
>LPARAMETERS cSourceImage,cOutputImage, nW, nH
>
>#DEFINE GDIPLUS_PIXELFORMAT_32bppPARGB       0x000E200B
>
>LOCAL  oImage, oGraphics, oBitmap, nW, nH
>oImage = NEWOBJECT('gpImage','_gdiplus.vcx')
>oImage.CreateFromFile( cSourceImage )
>oBitmap = NEWOBJECT('gpBitmap', '_gdiplus.vcx')
>oGraphics = NEWOBJECT('gpGraphics', '_gdiplus.vcx')
>oBitmap.Create( nW, nH, GDIPLUS_PIXELFORMAT_32bppPARGB)
>oGraphics.CreateFromImage(oBitmap)
>oGraphics.DrawImageScaled( oImage, 0, 0, nW, nH)
>oBitmap.SaveToFile( cOutputImage, 'image/png')
>
>
>replace image/png if you want

Thanks Dorin !

I have adapted the code in order to have blank spaces on sides to preserve the original ratio of the picture.
Here is the code, perharps useful for someone :
=ResizeImage("test.jpg","new.jpg",96,96)

PROCEDURE ResizeImage
LPARAMETERS cSourceImage,cOutputImage,nThumbWidth,nThumbHeight

#DEFINE GDIPLUS_PIXELFORMAT_32bppPARGB       0x000E200B

LOCAL oImage,oGraphics,oBitmap,nThumbWidth,nThumbHeight,nImgWidth,;
nImgHeight,nDestX,nDestY,nDestW,nDestH,m.nFact,nResizHeight,nSpace,nResizWidth
      
m.oImage = NEWOBJECT('gpImage','_gdiplus.vcx')
m.oImage.CreateFromFile(cSourceImage)
m.oBitmap = NEWOBJECT('gpBitmap','_gdiplus.vcx')
m.oGraphics = NEWOBJECT('gpGraphics','_gdiplus.vcx')
m.oBitmap.Create(nThumbWidth,nThumbHeight,GDIPLUS_PIXELFORMAT_32bppPARGB)
m.oGraphics.CreateFromImage(oBitmap)

m.nImgWidth=m.oImage.ImageWidth
m.nImgHeight=m.oImage.ImageHeight
DO case
   CASE m.nImgWidth > m.nImgHeight
      m.nFact=(m.nImgWidth-m.nThumbWidth)/m.nImgWidth
      m.nResizHeight=m.nImgHeight-(m.nImgHeight*m.nFact)
      m.nSpace=(nThumbHeight-m.nResizHeight)/2
      m.nDestX=0
      m.nDestY=m.nSpace
      m.nDestW=m.nThumbWidth
      m.nDestH=m.nResizHeight
      
   CASE m.nImgWidth < m.nImgHeight
      m.nFact=(m.nImgHeight-m.nThumbHeight)/m.nImgHeight
      m.nResizWidth=m.nImgWidth-(m.nImgWidth*m.nFact)
      m.nSpace=(nThumbWidth-m.nResizWidth)/2
      m.nDestX=m.nSpace
      m.nDestY=0
      m.nDestW=m.nResizWidth
      m.nDestH=m.nThumbHeight

   CASE m.nImgWidth = m.nImgHeight
      m.nDestX=0
      m.nDestY=0
      m.nDestW=m.nThumbWidth
      m.nDestH=m.nThumbHeight
ENDCASE
m.oGraphics.DrawImageScaled(m.oImage, m.nDestX, m.nDestY, m.nDestW, m.nDestH)
m.oBitmap.SaveToFile(m.cOutputImage,"image/jpeg","quality=90")
ENDPROC
A last question : Do you know how to have a white background (sides) for jpg thumbnails ?
Thanks
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform