Author
|
Topic: JPEG, PNG, GIF and URL Viewer
|
Chris Boss Administrator
|
posted 05-07-2008 07:02 PM
Here is a quick and easy way to display Jpeg, GIF and PNG images in EZGUI using the Listview control background. You can also download an image via an URL.The following code will allow you to select (via Open file dialog) a Jpeg (JPG), GIF or PNG image and display it in the listview control. If you cancel the open file dialog, the code defaults and loads an image from my web site via a URL. code:
#COMPILE EXE #DIM ALL ' This is helpful to prevent errors in coding ' -------------------- #INCLUDE "C:\ezgui40pro\includes\ezgui40.inc" ' EZGUI Include file for Declares ' -------------------- ' ************************************************************************************* ' Code Generator Defined Constants and Declares ' ************************************************************************************* DECLARE FUNCTION Main_Initialize(BYVAL VerNum&) AS LONG DECLARE SUB EZ_FORM1_Display(BYVAL Parent$) DECLARE SUB EZ_FORM1_Design() DECLARE SUB EZ_FORM1_ParseEvents(CID&, CMsg&, CVal&, Cancel&) DECLARE SUB FORM1_Events(CID&, CMsg&, CVal&, Cancel&) ' ------------------------------------------------ %FORM1_LISTVIEW1 = 100 %FORM1_SELBUTTON = 105 DECLARE SUB FORM1_LISTVIEW1_Events(MyID&, CMsg&, CVal&, Cancel&) DECLARE SUB FORM1_SELBUTTON_Events(MyID&, CMsg&, CVal&, Cancel&) ' -------------------- #INCLUDE "C:\ezgui40pro\includes\ezwmain.inc" ' EZGUI Include file for WinMain ' -------------------- ' SUB EZ_Main(VerNum&) ' (PROTECTED) IF Main_Initialize(VerNum&) THEN EZ_FORM1_Display "" END IF END SUB ' SUB EZ_DesignWindow(FormName$) ' (PROTECTED) SELECT CASE FormName$ CASE "FORM1" EZ_FORM1_Design CASE ELSE END SELECT END SUB ' SUB EZ_Events(FormName$, CID&, CMsg&, CVal&, Cancel&) ' (PROTECTED) SELECT CASE FormName$ CASE "FORM1" EZ_FORM1_ParseEvents CID&, CMsg&, CVal&, Cancel& CASE ELSE END SELECT END SUB ' FUNCTION Main_Initialize(BYVAL VerNum&) AS LONG LOCAL RV& RV&=1 FUNCTION=RV& END FUNCTION ' SUB EZ_FORM1_Display(BYVAL Parent$) ' (PROTECTED) EZ_Color -1, -1 EZ_Form "FORM1", Parent$, "Listview Image Display", 0, 0, 75, 29, "C" END SUB ' SUB EZ_FORM1_Design() ' (PROTECTED) LOCAL CText$ EZ_Color-1,-1 EZ_UseFont 4 EZ_ListView %FORM1_LISTVIEW1, 2, 1.25, 71, 23, "Column 1{15}|Column 2{15}{C}|Column 3{15}{R}|", "PSTV" ' ----------------------------------------------- EZ_Color-1,-1 EZ_UseFont 4 EZ_Button %FORM1_SELBUTTON, 46, 25.5, 27, 2.25, "Select Image", "T" ' ----------------------------------------------- END SUB ' SUB EZ_FORM1_ParseEvents(CID&, CMsg&, CVal&, Cancel&) ' (PROTECTED) SELECT CASE CID& CASE %EZ_Window FORM1_Events CID&, CMsg&, CVal&, Cancel& CASE %FORM1_LISTVIEW1 FORM1_LISTVIEW1_Events CID&, CMsg&, CVal&, Cancel& CASE %FORM1_SELBUTTON FORM1_SELBUTTON_Events CID&, CMsg&, CVal&, Cancel& CASE ELSE FORM1_Events CID&, CMsg&, CVal&, Cancel& END SELECT END SUB ' SUB FORM1_Events(CID&, CMsg&, CVal&, Cancel&) SELECT CASE CID& CASE %EZ_Window SELECT CASE CMsg& CASE %EZ_Loading CASE %EZ_Loaded CASE %EZ_Started CASE %EZ_Close CASE ELSE END SELECT CASE ELSE END SELECT END SUB ' SUB FORM1_LISTVIEW1_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Selected CASE ELSE END SELECT END SUB ' '<<SAVE>> SUB EZ_SetLVBackImage(BYVAL FormName$, BYVAL CID&, BYVAL ImagePath$, BYVAL IProp$) DIM DT(1 TO 6) AS LONG DT(1)=&H0002 DT(2)=0 DT(3)=STRPTR(ImagePath$) DT(4)=0 DT(5)=0 DT(6)=0 EZ_SendMessage FormName$, CID&, &H1044, 0, VARPTR(DT(1)) END SUB ' FUNCTION EZ_GetLVBackImage(BYVAL FormName$, BYVAL CID&) AS STRING LOCAL hBmp&, RV&, T AS ASCIIZ * 1025 DIM DT(1 TO 6) AS LONG DT(1)=&H0001 DT(2)=0 DT(3)=VARPTR(T) DT(4)=1024 DT(5)=0 DT(6)=0 RV&=EZ_SendMessageR(FormName$, CID&, &H1045, 0, VARPTR(DT(1))) FUNCTION=T END FUNCTION '<<END>> ' SUB FORM1_SELBUTTON_Events( MyID&, CMsg&, CVal&, Cancel&) SELECT CASE CMsg& CASE %EZ_Click LOCAL F$ F$=EZ_OpenFile("Form1", "Select Image", "", "Image Files (gif,jpg,png)|*.gif;*.jpg;*.png|", "ZI") IF F$<>"" THEN EZ_SetLVBackImage "Form1", %FORM1_LISTVIEW1, F$, "" MSGBOX EZ_GetLVBackImage("Form1", %FORM1_LISTVIEW1) ELSE ' get image via internet EZ_SetLVBackImage "Form1", %FORM1_LISTVIEW1, "http://cwsof.com/dialog1.png", "" MSGBOX EZ_GetLVBackImage("Form1", %FORM1_LISTVIEW1) END IF CASE ELSE END SELECT END SUB
No API includes are required for this code. The code will only work with PB 7.0 or later. |
Brian Reynolds Member
|
posted 05-28-2008 03:13 AM
Chris, I'm utilising your picture viewer so my wife can easily scan through the huge number of photos she takes. Is it possible to reduce the pixel size so a jpeg or other picture file will fit into the canvas size I am using? I can convert the pictures bitmaps and then reduce them but this tends to slow the process somewhat. Brian.
|
Chris Boss Administrator
|
posted 05-28-2008 09:18 AM
I don't believe the listview can do that.The listview is very limited. If you plan to work with graphic images of varied formats, it is best to get a dedicated image tool, like Small Animals image DLL to do the work. Windows has internal support for JPEG, GIF and PNG via the IPicture interface in the operating systems OLE DLL's. In the past I shyed away from using IPicture because of issues with patents on GIF and now JPEG. Microsoft is very vague about the use of this functionality (not even in the API docs), since they use it internally in their software (ie. IExplorer). The patent for GIF has run out and the JPEG one may run out before long. Dedicated image tools , especially those by well known companies (ie. ULead) tend to have taken into consideration all the ramifications of patents and other stuff. They also provide more extensive support for different formats, conversions, etc.
| |