Re: Load and Display a JPG Image
- Posted by m_sabal May 10, 2013
- 1604 views
Using Win32Lib
include win32lib.ew include gdiplus.ew -- Library by Al Getz. object imageBox atom pImage imageBox = createEx(Group,"Style Image",CSEntryTab,405,currentVOffset+5,390,370,0,0) pImage = -1
procedure clearImage() object junk if pImage > 0 then junk = GdipDisposeImage(pImage) pImage = 0 setPenColor(imageBox,getPixel(imageBox,2,2)) drawRectangle(imageBox,1,0,0,400,400) end if end procedure procedure paintStyleImage(integer self, integer event, sequence params) object result atom p4, iwidth, iheight, factor atom imageBoxGDC if pImage<=0 then return end if if length(params)=0 or params[1]!=WM_PAINT then return end if p4 = allocate(4) result = GdipCreateFromHWND(getHandle(imageBox),p4) if result=0 then imageBoxGDC=peek4u(p4) else imageBoxGDC=0 end if result=GdipGetImageWidth(pImage,p4) iwidth = peek4u(p4) result=GdipGetImageHeight(pImage,p4) iheight = peek4u(p4) free(p4) --iwidth = iwidth / 1.2 --iheight = iheight / 1.2 --result = GdipDrawImageRectI(imageBoxGDC,pImage, 30,30,iwidth,iheight) if iheight > 330 then factor = 330 / iheight iwidth = floor(iwidth * factor) iheight = floor(iheight * factor) end if if iwidth > 350 then factor = 350 / iwidth iwidth = floor(iwidth * factor) iheight = floor(iheight * factor) end if result = GdipDrawImageRectI(imageBoxGDC,pImage, 30,30,iwidth,iheight) end procedure procedure loadImage(sequence imagepath) if length(imagepath)>0 then ppImage = allocate(4) imagepathU = AnsiToUnicode(imagepath) result = GdipLoadImageFromFile(imagepathU,ppImage) FreeUnicode(imagepathU) if result=0 then pImage=peek4u(ppImage) else pImage=0 end if free(ppImage) paintStyleImage(-1,-1,{}) else setText(imageBox,"No Image") end if end procedure setHandler(imageBox,w32HAfterEvent,routine_id("paintStyleImage"))