Bugs:
GdipLoadPictureFile unknown. Need link.
GetImageSize unknown. Need code or link.
id(15 hDlg). What is 15?
Bitmap handle management:
1. Does not delete the source bitmap. Use flag LR_COPYDELETEORG with CopyImage.
2. STM_SETIMAGE does not delete previous bitmap. DeleteObject SendMessage(...).
3. The __GdiHandle-- line supports just single bitmap in thread. Maybe use array...
Optimizations:
GetImageSize - use bitmap handle, not file. Example:
Function GetBitmapRect
;/ function#str&imageFileData [backColor] [flags] ;;backColor: 0xAARRGGBB or ColorARGB(red green blue alpha). flags: 1 DDB
;Loads image data (image file in memory) and returns GDI bitmap handle. ;Returns 0 if failed. ;If the image has transparent areas, uses backColor as background color. Alpha remains. ;The returned bitmap later must be deleted with DeleteObject. Or assign to a __GdiHandle variable, it calls DeleteObject automatically. ;Supports all GDI+ formats: BMP, GIF, JPEG, PNG, TIFF, ICON, WMF, EMF, EXIF.
#compile"__Gdip" GdipBitmap b if(!b.FromMemory(imageFileData))ret ret b.GetHBITMAP(backColor flags)
;;set up a few things int button_start_x=200 int button_w=60 int button_h=12 int max_images=10 int- wParam_button=4;;sets the start point for the id of the buttons for wParam logic
ARRAY(str)- a
GetFilesInFolder(a "$common pictures$""*.jpg"4) if a.len=0 ,GetFilesInFolder(a "$my pictures$""*.jpg")
;/ function#str&imageFileData [backColor] [flags] ;;backColor: 0xAARRGGBB or ColorARGB(red green blue alpha). flags: 1 DDB
;Loads image data (image file in memory) and returns GDI bitmap handle. ;Returns 0 if failed. ;If the image has transparent areas, uses backColor as background color. Alpha remains. ;The returned bitmap later must be deleted with DeleteObject. Or assign to a __GdiHandle variable, it calls DeleteObject automatically. ;Supports all GDI+ formats: BMP, GIF, JPEG, PNG, TIFF, ICON, WMF, EMF, EXIF.
#compile"__Gdip" GdipBitmap b if(!b.FromMemory(imageFileData))ret ret b.GetHBITMAP(backColor)
NOTE: had to remove "flags" from ret b.GetHBITMAP(backColor flags) in GdipLoadPictureFileFromMemory to get to run. Perhaps you have updated GDI+ since I've downloaded last.
Updated above for your review. Obviously I hadn't seen function "StaticImageControlSetBitmap"
How can I test for memory leaks? Is it just the "Memory (Private Working Set)" going up in the task manager?
Essentially I'm trying to make sure the image fits in the dialog even if it is huge. Don't want to crash machines using this, so I really hope I have sealed that leak up ;-)
In this case it is a GDI handle. On Windows 7 in Task Manager processes tab you can add column 'GDI handles'. If macros leak GDI objects (bitmaps, brushes etc), the number will grow. Normally the number must be the same before and after macro, although sometimes it may change because QM also uses GDI objects.
Your function still leaks bitmaps. Does not use LR_COPYDELETEORG.
I see, hb=CopyImage(hb 0 width height LR_COPYDELETEORG)
WIthout using that flag the original image was hanging around
Updated functions above. When I run the memory of QM does not grow and the GDI objects goes up on load but then right back down. Looks good to me!
Thank you so much for helping out. I would have never known what to do about that. Now I have to go back through all my code I've ever written and look for memory leaks.
I really didn't understand what memory leaks were or how to fix them before. I only knew they were BAD!
This has been a terrific exercise and learning experience. Finally I can load images into dialogs on the fly!!
P.S. I know this function uses CopyImage to resize, I originally started off trying to figure out resizing with GDI+ but couldn't get anything to work. The GDI+ variables and functions all look like a foreign language to me.
I'd really like to see some GDI+ functions for resize, crop, and rotate ;-)
,caseWM_INITDIALOG ,GdipBitmap-- t_im ,OpenClipboard(hDlg) ,t_im.FromHBITMAP(GetClipboardData(CF_BITMAP)) ,CloseClipboard ,if(!t_im)out"failed to get bitmap from clipboard" ,;note: don't need to delete bitmap when from clipboard
1. Can GDI handle crop, rotate resize on its own?
2. GDI versus GflAx. Advice, opinion?
3. I can do t_im.Save to save to a file. Is saved picture format done automagically depending only on
file extension, or is there more?
My opinion:
GDI - often difficult, need more code, in some cases low quality, not everything possible.
GDI+ - easier, higher quality. However QM does not have easy functions for everything. Often need to use GDI+ flat API, which is not well documented.
GflAx - easiest (in most cases). I think, good quality too.
Acknowledged.
I have several functions using GflAx which
Work great. The major annoyance is that it seems
I must install it on every PC i want use it, unlike GDI
routines. If I make an exe from a macro i'm done.
I struggle in GDI to resize a GdiBitmap say 300x300.
Some code?
No, it must be separate file. If don't want 2 files, can add dll to exe resources, at run time extract to a temporary file and use the file with _create.
#compile"__Gdip" GdipBitmap-- t_im t_out OpenClipboard(0)
t_im.FromHBITMAP(GetClipboardData(CF_BITMAP)) CloseClipboard if(!t_im)out"failed to get bitmap from clipboard" ;note: don't need to delete bitmap when from clipboard
PAINTSTRUCT ps BeginPaint0&ps
t_im.DrawResize(ps.hDC 003003007)
EndPaint0&ps
t_out.FromHBITMAP(_i)
t_out.Save("q:\g.png")
Miss the code to go from ps.HDC to t_out.save, making t_out from ps.HDC...
#compile"__Gdip" GdipBitmap t_im t_out OpenClipboard(0)
t_im.FromHBITMAP(GetClipboardData(CF_BITMAP)) CloseClipboard if(!t_im)out"failed to get bitmap from clipboard" ;note: don't need to delete bitmap when from clipboard
__MemBmp mb.Create(300300)
t_im.DrawResize(mb.dc 003003007)
t_out.FromHBITMAP(mb.bm)
t_out.Save("q:\g.png")
run"q:\g.png"
Actually can resize only with GDI+, but this works too.
dialog_gdi_plus_resize_image seems to only allow one image via this method i.e. if I try to add it doesn't appear but if I take out the first call, it does.
Also, I typically would have second image in t_im e.g. t_im2
Any way to have more than one image in the dlg?
Thanks, S