Posts: 1,000
Threads: 253
Joined: Feb 2008
Need a way to take a list of images and combine them into a single file.
Usually, I work with gFlax, but the merge function overlays the images without resizing the canvas. I've played around with it quite a bit without the correct results.
I think using the GDI+
http://www.quickmacros.com/forum/showthr...p?tid=3703 this could be easily achieved, but I don't fully understand how to use the functions yet.
Please help me out with an example.
thanks,
Jim
Posts: 12,086
Threads: 142
Joined: Dec 2002
Macro
Macro1991
#compile "__Gdip"
;get list of files
ARRAY(str) a
GetFilesInFolder a "Q:\test" "\.(bmp|png|gif|jpg|jpeg|ico)$" 0x10000
;out af; ret
;calculate dimensions of destination image
int i w h width height
GdipImage im ;;used for source images
ARRAY(int) aa.create(a.len) ;;used for positions of images
for i 0 a.len
,if(!im.FromFile(a[i])) out "failed to load: %s" a[i]; continue
,aa[i]=height
,w=im.width; if(w>width) width=w
,h=im.height; height+h
;create empty destination image
GdipBitmap b.CreateEmpty(width height) ;;used to draw images and save
GdipGraphics g.FromImage(b) ;;need for GDIP functions
;draw images
for i 0 a.len
,if(w*h=0) continue ;;if failed to load above
,if(!im.FromFile(a[i])) out "failed to load: %s" a[i]; continue
,GDIP.GdipDrawImageI(g im 0 aa[i])
;save
if(!b.Save("$desktop$\test55.png")) end "saving"
;see what we have
run "$desktop$\test55.png"
Posts: 1,000
Threads: 253
Joined: Feb 2008
Thanks! This is a terrific thing!
I forgot to mention, I'd like to standardize all the widths, so how would you go about setting a width and resizing all of the images while maintaining aspect ratio?
Edit: I guess I could use gFlax to standardize images and then use your function to merge.
-Jim
Posts: 12,086
Threads: 142
Joined: Dec 2002
Look for a resizing function in 'GDIP.' list.
Maybe at first google how to do with GDI+.
Without GDI+ its easy to resize with CopyImage. But quality is not the best. Need bitmap handle. You can get it from GDI+ and set to GDI+ again. Don't forget to DeleteObject.
Posts: 1,000
Threads: 253
Joined: Feb 2008
Is the GDI+ set to 96dpi by default?
When I ran the original function in this thread, one of the images was bigger blown out, so somehow it must be specified differently than the rest with the dpi and things.
With gFlax had to set dpi to 96 and set "SaveKeepMetadata=0"
Got it working with gFlax. I already have a bunch of functions using that, but I am interested in resizing and cropping functions using GDI+