Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dialog_loadImage
#5
Gintaras, Does this look better? Thanks for your help!!

-Jim
Function Dialog_Image
Code:
Copy      Help
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages

;;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")

if a.len>max_images
,int- Buttons=max_images
else
,Buttons=a.len
for int'i 0 Buttons
,str sName.getfilename(a[i])
,str dlg_Button=
,F
,;{i+wParam_button} Button 0x54032000 0x0 0 {button_start_x+(i*button_h)} {button_w} {button_h} "{sName}"
,str dlg_Buttons.addline(dlg_Button)
dlg_Buttons.trim
str DIALOG=
F
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 302 372 "Dialog"
;3 Static 0x5400000E 0x0 0 0 300 200 ""
;{dlg_Buttons}
;END DIALOG
;DIALOG EDITOR: "" 0x2030502 "" "" "" ""
out DIALOG
str controls = "3"
str sb3
if(!ShowDialog(DIALOG &Dialog_Image &controls)) ret
ret
;messages
sel message
,case WM_INITDIALOG
,str imageFileData.getfile(a[0])
,hWnd_LoadImageFromMemory(imageFileData id(3 hDlg) 400 400)
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
if (wParam>=wParam_button and wParam<=wParam_button+Buttons)
,imageFileData.getfile(a[wParam-wParam_button])
,hWnd_LoadImageFromMemory(imageFileData id(3 hDlg) 400 400)
sel wParam
,case IDOK
,case IDCANCEL
ret 1

Function hWnd_LoadImageFromMemory
Code:
Copy      Help
function ~imageFileData hWnd [double'height] [double'width]
;;hWnd is id of static dialog element


int hb=GdipLoadPictureFileFromMemory(imageFileData)


BITMAP bi
if(GetObjectW(hb sizeof(bi) &bi))
,int w=bi.bmWidth
,int h=bi.bmHeight
if (height and width)
,if w>h;height=(width/w)*h
,if h>w;width=(height/h)*w
else height=h;width=w
hb=CopyImage(hb 0 width height LR_COPYDELETEORG)
StaticImageControlSetBitmap hWnd hb
DeleteObject hb

Function GdipLoadPictureFileFromMemory
Code:
Copy      Help
;/
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.

Member function GdipBitmap.FromMemory
Code:
Copy      Help
function'GDIP.GpBitmap* str&imageFileData

;Creates this bitmap from image data (image file in memory).
;Supported formats: BMP, GIF, JPEG, PNG, TIFF, ICON, WMF, EMF, EXIF.


if(!GdipInit) ret
Delete

__Stream x.CreateOnHglobal(imageFileData imageFileData.len); err end _error
_hresult=GDIP.GdipCreateBitmapFromStream(x +&m_i)
ret +m_i


Attached Files
.qml   Dialog_Image.qml (Size: 3.08 KB / Downloads: 491)


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)