TestImg Example

TestImg Example

Postby Rick Lipkin » Mon Jan 09, 2012 8:55 pm

To All

Using a slightly modified TestImage.prg from the \samples folder .. I am selecting an Image .. it Loads .. and I am asking if the User wants to Keep the selected File ( YesNo ) ..

In Order for the User to see the file the oImage:LoadBmp( gcFile ) has to load. The only way I could figure out how to Work the No Save .. was to Issue the oImage:Destroy() .. Which works.

When you go back in the same session and re-select another Image .. The oImage:LoadBmp( gcFile ) fails to load the new Image .. I am sure it has to do with the Destroy().

Is there a method I am missing in Timage or TBitmap Class that will allow me to just Nil out the oImage Object and Refresh it with a Blank screen ??

Thanks
Rick Lipkin

Code: Select all  Expand view  RUN

#include "FiveWin.ch"
#include "Image.ch"

//----------------------------------------------------------------------------//

function Main()

LOCAL oDlg, oImage, saying, lSetAlpha := .t.

If .not. file("FreeImage.dll")
   Saying := "Sorry .. FreeImage.DLL is not available"
   MsgInfo( saying )
   Return(.f.)
Endif


//   setalpha( .f. )

DEFINE DIALOG oDlg FROM 0, 0 TO 22, 60 ;
      TITLE FWDESCRIPTION + " JPG,JIF,GIF,BMP,DIB,RLE,TGA,PCX support!"

   @ 0, 0 IMAGE oImage SIZE 150, 150 OF oDlg SCROLL // ADJUST

   oImage:Progress( .f. )

   @ 1, 28 BUTTON "Select Image" SIZE 50,10 OF oDlg ACTION GetImage( oImage,oDlg )

   @ 2, 28 BUTTON "Print" SIZE 50,10 OF oDlg ACTION PrintImage( oImage )

   @ 3, 28 BUTTON "Copy" SIZE 50, 10 OF oDlg ;
      ACTION oImage:CopyToClipboard()

   @ 4, 28 BUTTON "Paste" SIZE 50, 10 OF oDlg ;
      ACTION ( oImage:LoadFromClipboard(), oImage:Refresh() )

   @ 5, 28 BUTTON "Save" SIZE 50, 10 OF oDlg ;
      ACTION ( oImage:SaveImage( "SAVED.JPG", 2, 25 ), MsgInfo( "saved as saved.jpg" ) )

   @ 6, 28 BUTTON "Exit" SIZE 50, 10 OF oDlg ACTION oDlg:End()

   @ 10, 26 CHECKBOX oImage:lStretch PROMPT "Stretch" SIZE 50, 10 OF oDlg ;
      ON CHANGE ( oImage:ScrollAdjust(), oImage:Refresh() )

   @ 11, 26 CHECKBOX lSetAlpha PROMPT "Set Alpha Channel" SIZE 80, 10 OF oDlg ;
      ON CHANGE ( SetAlpha( lSetAlpha ), oImage:Refresh() )


ACTIVATE DIALOG oDlg CENTER

return nil

//----------------------------------------------------------------------------//

function GetImage( oImage,oDlg )

local nLen,nStart,cPic,cFileName
local gcFile,cOldFile

gcFile := cGetFile( "Bitmap (*.bmp)| *.bmp|" +         ;
                             "DIB   (*.dib)| *.dib|" +          ;
                             "PCX   (*.pcx)| *.pcx|"  +         ;
                             "JPEG  (*.jpg)| *.jpg|" +          ;
                             "GIF   (*.gif)| *.gif|"  +         ;
                             "TARGA (*.tga)| *.tga|" +          ;
                             "RLE   (*.rle)| *.rle|" +          ;
                             "All Files (*.*)| *.*"             ;
                            ,"Please select a image file", 4 )

if ! Empty( gcFile ) .and. File( gcFile )

   oImage:LoadBmp( gcFile )
   oDlg:ReFresh()
   SysReFresh()

   If rat( "\", gcFile ) > 0
      nLen   := len( gcFile)
      nStart := rat( "
\", gcFile )
      cPic := substr( gcFile,nStart+1, (nLen-nStart))
   Endif

   Saying := "
Are you SURE you want to Save this File"+chr(10)
   Saying += cPic+"
?"

   If MsgNoYes( saying )

   Else
      oImage:Destroy()
      oDlg:ReFresh()
      SysReFresh()
   Endif

Endif

Return(nil)

//----------------------------------------------------------------------------//

function PrintImage( oImage )

   local oPrn

   PRINT oPrn NAME "
Image Printing" PREVIEW
      PAGE
         oPrn:SayImage( 0, 0, oImage )
      ENDPAGE
   ENDPRINT

return nil

//----------------------------------------------------------------------------//

procedure AppSys   // XBase++ requirement

return

//------------------
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: TestImg Example

Postby ukoenig » Mon Jan 09, 2012 11:22 pm

Rick,

Shows a empty Area of a unselected Image :

Image

Image

Code: Select all  Expand view  RUN

#include "FiveWin.ch"
#include "Image.ch"

STATIC c_path

FUNCTION MAIN()
LOCAL oDlg, oImage, cImage := SPACE(30), hDC, oFont, oGet

c_path := CURDRIVE() + ":\" + GETCURDIR()
oFont  := TFont():New("
Arial",,-14,.F.,.T. ,,,,.F. )

If .not. file("
FreeImage.dll")
   Saying := "
Sorry .. FreeImage.DLL is not available"
   MsgInfo( saying )
   Return(.f.)
Endif

DEFINE DIALOG oDlg FROM 50, 50 TO 400, 600 PIXEL ;
TITLE FWDESCRIPTION + "
JPG,JIF,GIF,BMP,DIB,RLE,TGA,PCX support!"

@ 10, 10 IMAGE oImage FILENAME NIL OF oDlg ;
SIZE 150, 120 PIXEL  ADJUST BORDER
oImage:cTooltip := "
Image"
oImage:bPainted := { |hDC| DRAW_IMG( oImage, hDC, cImage ) }

@ 150, 10 GET oGet VAR cImage OF oDlg  SIZE 100, 15 PIXEL FONT oFont

@ 140, 180 BTNBMP oBtn4 OF oDlg ;
SIZE 80, 25 PIXEL 2007 ;
NOBORDER ;
PROMPT "
&Image-Select" ;
FILENAME c_path + "
\Images\Select.Bmp" ;
ACTION  ( cFilter := "
JPG (*.jpg)|*.jpg|" + ;
               "
BMP (*.bmp)|*.bmp|" + ;
               "
PNG (*.png)| *.png|" + ;
               "
TIFF (*.tiff)| *.tiff|" + ;
               "
DDS (*.dds)| *.dds|" + ;
               "
IFF (*.iff)| *.iff|" + ;
               "
PCX  (*.pcx)| *.pcx|" + ;
               "
PPM (*.ppm)| *.ppm|" + ;
               "
PSD (*.ppm)| *.psd|" + ;
               "
SGI  (*.sgi)| *.sgi|" + ;
               "
TARGA (*.tga)| *.tga|", ;
    cNewBITM := cGetFile32( cFilter,"
Select a Picture" ,,  "\" + CurDir()+ "\Images" ), ;
    IIF( EMPTY( cNewBITM ), ;
          ( MsgAlert( "
No file selected !","ATTENTION" ), cImage := " " ), ;
          cImage := cFileNoPath( cNewBITM ) ), ;
          oGet:Refresh(), oImage:Refresh() ) ;              
FONT oFont ;
LEFT

ACTIVATE DIALOG oDlg CENTER

oFont:End()

RETURN NIL

//------------- Image-Brush -----------

FUNCTION DRAW_IMG( oImage, hDC, cImage )
LOCAL oBrush
LOCAL aRect := GETCLIENTRECT( oImage:hWnd )

IF FILE( c_path + "
\Images\" + cImage )
    DEFINE IMAGE oBrush FILENAME c_path + "
\Images\" + cImage
    PalBmpDraw( hDC, 0, 0, oBrush:hBitmap, , aRect[4], aRect[3] )
    oBrush:End()
ELSE
    IF !EMPTY(cImage)
        MsgAlert( "
File : " + cImage + CRLF + ;
                       "
does not exist" + CRLF + ;
                       "
to show Image !", "ATTENTION" )
    ENDIF
ENDIF

RETURN( NIL )


A better looking Solution :

Image

Image

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: TestImg Example

Postby Rick Lipkin » Wed Jan 11, 2012 3:01 pm

Uwe

Thank you for your example .. I was able to successfully adapt it to my application .. As you mentioned .. It probably would have been easier and simpler to have a 'blank' bitmap .. Just define it once with the 'blank' bitmap .. then ReFresh() it if the user adds a real picture.

In any case .. your code was excellent !

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: TestImg Example

Postby ukoenig » Wed Jan 11, 2012 9:22 pm

Rick,

fine to hear that it works for You.
I will place a much better one in the Forum.
Complete Source is included.
( I still have to test some calculations )

Pictures are embedded inside a Frame with Border and Shadow.
The Picture is displayed for a non selected ( empty ) Image :
Frames of smaller Images are adjusted to Imagesize.

Image

To keep proportions, Height or Width is adjusted.
This Sample shows a resized Width and the Height adjusted to the new Width

Image

This Sample uses the original Image-size.

Image

Best Regards
Uwe :lol:
Last edited by ukoenig on Thu Jan 12, 2012 2:27 pm, edited 1 time in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: TestImg Example

Postby ukoenig » Thu Jan 12, 2012 12:46 pm

Added a Image-filter, to view alphablended Button-images with possible Zoom-factor.

Selecting NO Button, shows ALL formats.
1, 1,5 or 2 shows / zooms BMP's with Alpha-channel :

Image

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: TestImg Example

Postby Rick Lipkin » Thu Jan 12, 2012 2:00 pm

Uwe

Looks awesome .. How did you get the Shadow to appear around your Image ?

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: TestImg Example

Postby ukoenig » Thu Jan 12, 2012 2:10 pm

Rick,

I use a VTITLE-frame with embedded Images or Brushes.
That makes is also possible, to use round Corners.
Some Calculations are needed for Adjustments.

Best Regards
Uwe :lol:
Last edited by ukoenig on Thu Jan 12, 2012 2:14 pm, edited 1 time in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: TestImg Example

Postby Rick Lipkin » Thu Jan 12, 2012 2:13 pm

Uwe

I am still using FWH 9.10 .. a bit behind the times .. could you elaborate further on Vtitle-frame for me ?

Thanks
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: TestImg Example

Postby ukoenig » Thu Jan 12, 2012 2:21 pm

Rick,

a Syntax-sample of the EMPTY-image ( nothing selected )
It also shows, how to add a < Watermark ( ? ) > on Top of a Image
with defined Size and Transparent-level :

I'm still looking for a Solution, to use alphablended BMP's for Brushes !!!.
For the Moment, only the use of plain Images without Alpha-channel is possible.


viewtopic.php?f=3&t=23253

Image

Code: Select all  Expand view  RUN

@  10, 10 TITLE oTitle SIZE 125, 125 of oDlg SHADOW BOTTOMRIGHT SHADOWSIZE 10
oTitle:lRound := .T.
oTitle:nClrLine1 := 128
oTitle:nClrLine2 := 0
// a Gradient background is used
// 1. added a Image 
oTitle:LoadBitmaps( c_path + "\Images\Computer.bmp", 20, 20, 220, 220, 255, , .T. )

// 2. A loop, to display the ? on top ( Watermark, using a alpha-blended BMP )
// Line by Line and from Col to Col :
// ----------------------------------------------------------------------------------------
nRow := 10
nCol := 5
nI_Width := 48
nI_Height := 48

DO WHILE nRow < 245
    nCol = 5
    DO WHILE nCol < 245
        oTitle:LoadBitmaps( c_path + "\Images\Empty1.bmp", nRow, nCol, , , , , .T. )
        nCol += nI_Height
    ENDDO
    nRow += nI_Width
ENDDO
 


Just a Sample, how to use VTitles.

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: TestImg Example

Postby ukoenig » Sat Jan 14, 2012 12:25 pm

Rick,
please have a look at :

viewtopic.php?f=3&t=23294

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 13 guests