1. Load and Display a JPG Image
- Posted by Jock Mar 03, 2013
- 1892 views
Does anyone have a simple example of loadin a jpg image from file and then displaying it in a window (using either win32Lib or wxEuphoria)? All the examples I've seen seem to be about converting or resizing. I'm using win7.
Many thanks
2. Re: Load and Display a JPG Image
- Posted by ssallen Mar 03, 2013
- 1898 views
I have used CXImage in the past and it makes it pretty easy if all you want to do is draw a jpg/gif/png/etc in a window:
global function getImageType(sequence xbytes) -- xbytes is first 5 bytes of file integer imgtype imgtype = 0 if xbytes[1] = 'ÿ' then if xbytes[2] = 'Ø' and xbytes[3] = 'ÿ' then imgtype = CXI_FORMAT_JPG end if elsif xbytes[2] = 'P' then if xbytes[3] = 'N' and xbytes[4] = 'G' then imgtype = CXI_FORMAT_PNG end if elsif xbytes[1] = 66 then if xbytes[2] = 77 then imgtype = CXI_FORMAT_BMP end if elsif xbytes[1] = 'G' then if xbytes[2] = 'I' and xbytes[3] = 'F' then imgtype = CXI_FORMAT_GIF end if else imgtype = CXI_FORMAT_UNKNOWN end if return imgtype end function
atom img, fimg, imgtyp sequence abytes fnumb = open("myimg.jpg", "rb") abytes = get_bytes(fnumb, 5) close(fnumb) imgtyp = getImageType(abytes) img = CXI_LoadImage("myimg.jpg", imgtyp, 0) if img < 1 then ret = message_box("Image load error!", "File is busted!", MB_OK) return -1 end if fimg = CXI_MakeBitmap(img, NULL) -- draw the image using whatever api you are using drawBitmap(Window1, fimg, 428, 308) -- win32lib CXI_FreeImage(fimg)
cxImage uses its own internal image format so make sure you use CXI_MakeBitmap - not using it will cause machine level exceptions.
Steve A.
3. Re: Load and Display a JPG Image
- Posted by mattlewis (admin) Mar 03, 2013
- 1893 views
Does anyone have a simple example of loadin a jpg image from file and then displaying it in a window (using either win32Lib or wxEuphoria)? All the examples I've seen seem to be about converting or resizing. I'm using win7.
Many thanks
Take a look at the trans_blit.exw demo that comes with wxEuphoria.
Matt
4. Re: Load and Display a JPG Image
- Posted by face1988 May 09, 2013
- 1680 views
- Last edited May 10, 2013
the following is C# image load sample
public static void LoadImageFromFileDemo() { string fileName = "c:/Sample.png"; REImage reImage = REFile.OpenImageFile(fileName); }check out: http://www.rasteredge.com/how-to/csharp-imaging/load-from-file/
5. Re: Load and Display a JPG Image
- Posted by m_sabal May 10, 2013
- 1605 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"))
6. Re: Load and Display a JPG Image
- Posted by DonCole May 11, 2013
- 1530 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"))
Where did CSEntryTab come from?
Don Cole
7. Re: Load and Display a JPG Image
- Posted by m_sabal May 12, 2013
- 1480 views
Where did CSEntryTab come from?
Don Cole
In my application, it happens to be a tab control. It could just as easily be a Window or any other container object.
8. Re: Load and Display a JPG Image
- Posted by irv May 30, 2013
- 1300 views
constant img = create(GtkImage,"myphoto.jpg") add(win,img)
OK, it's not exactly as specified, but it WILL work on Windows 7, using libgtk3.