WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

GDI Image Resize


Question:

Guido wrote several UDFs for GDI+ about a year ago (posted in the tech database). They have been very helpful, but now I need more...

I need to resize a jpg (basically create a large thumbnail). I have tried Pixie, but the JPG compression is way too high for the quality I need. The images need to be jpegs - not bmps - or compression would not be an issue. I also need it to be as fast as possible (there are thousands of jpgs to convert), so I thought GDI+ might be the way to go.

Has anyone tried to resize an image with GDI+?

Answer:

#definefunction gpGetImageThumbnail(agp, GpImage, thumbWidth, thumbHeight)
	bthumbImage = binaryalloc(4)
	r = dllcall(agp[0], long:"GdipGetImageThumbnail", long:GpImage, long:thumbWidth, long:thumbHeight, lpbinary:bthumbImage, lpnull, lpnull)
	thumbImage = binarypeek4(bthumbImage, 0)
	binaryfree(bthumbImage)
	
	if r==0 then return thumbImage
	else return 0
#endfunction 

to use it, in the JPEG encode example i posted do something like,

;load image
img = gpLoadImageFromFile(agp, inFile)

imgThumbnail = gpGetImageThumbnail(agp, img, 100, 100)

gpSaveImageToFile(agp, imgThumbnail, outFile, bJPEG, 50)

gpDisposeImage(agp, img)
gpDisposeImage(agp, imgThumbnail)
Note that all the code is omitted but i tested it and it works, you will need to do some math if you want to keep the aspect ratio. Reference: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/Samples~from~Users+GDI~Image~Encoding.txt

- Guido


Article ID:   W17219
File Created: 2014:07:18:09:51:38
Last Updated: 2014:07:18:09:51:38