Another GDI+ problem
- Posted by buzzo Jan 10, 2012
- 1307 views
In the following code, ExportImage() returns status=10 .. it write an empty (0kb) file.. sure would like to have it return 0.. Are "other steps" needed to convert this jpg to a bmp? The DoGraphics() procedure performs just fine..
--testGDI-02.exw -- 1-10-2012 include machine.e include misc.e include Win32Lib.ew include dll.e include wildcard.e include gdiplus_Win98,XP.ew without warning sequence screenSize screenSize = getCtlSize( Screen ) -- get screen size global integer screenWidth screenWidth = screenSize[1] -- width global integer screenHeight screenHeight = screenSize[2] -- height integer winWidth winWidth = 1280 -- MAIN WINDOW WIDTH integer winHeight winHeight = 900 -- MAIN WINDOW HEIGHT integer xWinPos xWinPos = floor((screenWidth - winWidth)/2) -- x postion on display for centering MAIN WINDOW integer yWinPos yWinPos = floor((screenHeight - winHeight)/2) -- y postion on display constant win = createEx( Window, "Relatives", 0, xWinPos, yWinPos, winWidth, winHeight, 0, 0 ), CrLf = { '\r', '\n' } --************ GdiPlus Specific Code *************** global atom status,ppGraphics,ppImage,pGraphics,pImage sequence LoadFilePath,SaveFilePath --,FilePath status=GdipInitialize() if status!=0 then puts(1,"Cant open a required dll\n") sleep(1) end if pImage=0 ppGraphics=allocate(4) ppImage=allocate(4) LoadFilePath="H:\\Euphoria\\relatives\\Genealogy\\JPark.jpg" SaveFilePath="H:\\Euphoria\\relatives\\Genealogy\\JPark-01.bmp" procedure ExportImage (sequence filePath) -- load an image and it save as a .bmp file atom p_encoderParams,p_filenameW,p_clsidEncoderW,lpFilePathW status=GdipCreateFromHWND(getHandle(win),ppGraphics) if status=0 then pGraphics=peek4u(ppGraphics) else pGraphics=0 end if if length(filePath)>0 then status=GdipDisposeImage(pImage) lpFilePathW=AnsiToUnicode(filePath) status=GdipLoadImageFromFile(lpFilePathW,ppImage) if status=0 then pImage=peek4u(ppImage) else pImage=0 end if end if p_encoderParams=NULL p_filenameW=AnsiToUnicode(SaveFilePath) p_clsidEncoderW=AnsiToUnicode("image/bmp") -- GdipSaveImageToFile(atom p_image,atom p_filename,atom p_clsidEncoder,atom p_encoderParams) status=GdipSaveImageToFile(pImage,p_filenameW,p_clsidEncoderW,p_encoderParams) puts(1,w32ToString(status)) puts(1,CrLf) free(ppGraphics) free(ppImage) FreeUnicode(lpFilePathW) FreeUnicode(p_filenameW) FreeUnicode(p_clsidEncoderW) end procedure procedure DoGraphics(sequence filePath) atom Width,Height,pUINT,pW,pH,lpFilePathW status=GdipCreateFromHWND(getHandle(win),ppGraphics) if status=0 then pGraphics=peek4u(ppGraphics) else pGraphics=0 end if if length(filePath)>0 then status=GdipDisposeImage(pImage) lpFilePathW=AnsiToUnicode(filePath) status=GdipLoadImageFromFile(lpFilePathW,ppImage) if status=0 then pImage=peek4u(ppImage) else pImage=0 end if end if pUINT=allocate(4) status=GdipGetImageWidth(pImage,pUINT) Width=peek4u(pUINT) status=GdipGetImageHeight(pImage,pUINT) Height=peek4u(pUINT) pW=100 pH=floor(Height*(pW/Width)) status=GdipDrawImageRectI(pGraphics,pImage,40,20,pW,pH) FreeUnicode(lpFilePathW) free(pUINT) free(ppGraphics) free(ppImage) end procedure procedure win_onPaint(integer Self, integer Event, sequence Params) atom editR=100 if editR=100 then DoGraphics(LoadFilePath) end if end procedure setHandler(win, w32HPaint, routine_id("win_onPaint")) ExportImage(LoadFilePath) ---------------- WinMain(win,Normal)