Drawing on a TImage and save (revamped) :-) [Solved]

Re: Drawing on a TImage and save (revamped) :-)

Postby Enrico Maria Giordano » Fri Apr 04, 2014 11:26 am

Uwe,

sorry, but I need to handle bigger images (3000 pixels).

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Drawing on a TImage and save (revamped) :-)

Postby ukoenig » Fri Apr 04, 2014 11:40 am

Enrico,

I will test using IMAGE-SCROLL
That means :
1. move to the area You want to show and draw.
DONT move again ( refreshes the image ), otherwise You will delete the painting.
I didn't test this solution.
I will find out, if the COMPLETE image with painting-position will be saved.

Best reagards
Uwe :?:
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: Drawing on a TImage and save (revamped) :-)

Postby Enrico Maria Giordano » Fri Apr 04, 2014 11:43 am

Uwe,

I need to draw programmatically. I can't use the scrollbar.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Drawing on a TImage and save (revamped) :-)

Postby Enrico Maria Giordano » Fri Apr 04, 2014 10:16 pm

Maybe solved! :-)

Code: Select all  Expand view
#include "Fivewin.ch"


#define SRCCOPY 13369376


FUNCTION MAIN()

    LOCAL oDlg, oImg

    DEFINE DIALOG oDlg;
           SIZE 800, 600

    @ 0, 0 IMAGE oImg;
           SIZE 100, 100;
           FILE "SFONDO.JPG";
           ADJUST

    @ 15, 0 BUTTON "Draw";
            ACTION DRAWIMG( oImg )

    @ 15, 20 BUTTON "Save";
             ACTION oImg:SaveImage( "MYIMAGETEST.JPG", 2 )

    ACTIVATE DIALOG oDlg;
             CENTER

    RETURN NIL


STATIC FUNCTION DRAWIMG( oImg )

    LOCAL hDC := oImg:GetDC()

    LOCAL nWidth  := oImg:nWidth()
    LOCAL nHeight := oImg:nHeight()

    LOCAL hMemDC := CREATECOMPATIBLEDC( hDC )

    LOCAL hMemBmp := CREATECOMPATIBLEBITMAP( hDC, nWidth, nHeight )

    LOCAL hBmpOld := SELECTOBJECT( hMemDC, hMemBmp )

    LOCAL hBitmap  := oImg:hBitmap
    LOCAL hPalette := oImg:hPalette

    LOCAL x, y

    PALBMPDRAW( hMemDC, 0, 0, hBitmap, hPalette, nWidth, nHeight )

    FOR y = 0 TO 99
        FOR x = 0 TO 159
            SETPIXEL( hMemDC, x, y, CLR_HRED )
        NEXT
    NEXT

    SELECTOBJECT( hMemDC, hBmpOld )

    DELETEDC( hMemDC )

    oImg:hBitmap = hMemBmp

    PALBMPFREE( hBitmap, hPalette )

    PALBMPNEW( oImg:hWnd, oImg:hBitmap, oImg:hPalette )

    oImg:Refresh()

    RETURN NIL


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Drawing on a TImage and save (revamped) :-)

Postby Enrico Maria Giordano » Sat Apr 05, 2014 8:41 am

Dear friends,

I have one more little problem: how to show the image during the drawing? In my sample, the drawn image is only shown at the end of the process.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Drawing on a TImage and save (revamped) :-)

Postby ukoenig » Sat Apr 05, 2014 10:29 am

Enrico,
now I understand, what You need.
Just a quick solution.
It will work, doing these changes ( blue ).
I think, You can change Your post to < SOLVED > :?:

It is possible, to make it much better !!!

I will post the extensions.
My other tool must wait :roll:

--------------------
--------------------


STATIC nPWidth, nPHeight

FUNCTION MAIN()
LOCAL oDlg, oImg, hDC
nPWidth := 200
nPHeight := 150
// vars, to be calculated with function
...
...
@ 0, 0 IMAGE oImg SIZE nPWidth, nPHeight ;
FILE c_path1 + "TEST.JPG" ADJUST
oImg:bPainted := { |hDC| ASPECT_RATIO(oImg) }

@ 15, 0 BUTTON "Draw";
ACTION DRAWIMG( oImg, hDC )
...
...
ACTIVATE DIALOG oDlg CENTER ;
ON INIT hDC := oImg:GetDC()


RETURN NIL

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

STATIC FUNCTION ASPECT_RATIO(oImg)

nPWidth := oImg:nWidth() * 0.5 // a wanted resize-factor to show the image on dialog
nPHeight := oImg:nHeight() * 0.5 // a wanted resize-factor to show the image on dialog
oImg:Refresh()

RETURN NIL


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

STATIC FUNCTION DRAWIMG( oImg, hDC )
//LOCAL hDC := oImg:GetDC() // must be deleted !!!
....
...

Painted on a image resized to 50 %

Image

Saved image 100 %

Image

just working on a screen-adjustment

Image


Best regards
Uwe :?:
Last edited by ukoenig on Mon Apr 07, 2014 3:28 pm, edited 2 times 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: Drawing on a TImage and save (revamped) :-)

Postby Enrico Maria Giordano » Sat Apr 05, 2014 5:51 pm

Uwe,

I don't understand. Can you build a compilable sample, please?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Drawing on a TImage and save (revamped) :-)

Postby ukoenig » Sat Apr 05, 2014 6:22 pm

Enrico,

completed with export-preview !

Code: Select all  Expand view

#include "Fivewin.ch"
#include "Image.ch"

#define SRCCOPY 13369376

FUNCTION MAIN()
LOCAL oDlg, oImg, hDC, oCbx1, oFont1
LOCAL oBtn1, oBtn2, oBtn3, oSay1, aSize := {}
LOCAL oTest, nOWidth, nOHeight, nPWidth, nPHeight, nResize

c_path := cFilePath(GetModuleFileName( GetInstance() ) )
c_path1 := c_path + "IMAGES\" // YOUR IMAGEPATH !!!!!

cWorkFile := c_path1 + "
TEST.JPG"
cDestFile := "
MYIMAGETEST"
nResize := 20
cResize := "
20 %"
cExtension := "
JPG"

DEFINE IMAGE oTest FILENAME cWorkfile
nOWidth := oTest:nWidth
nOHeight := oTest:nHeight
oTest:End()
nPWidth := nOWidth * ( nResize / 100 )
nPHeight := nOHeight * ( nResize / 100 )

DEFINE FONT oFont1 NAME "
Arial" SIZE 0, -12 BOLD

DEFINE DIALOG oDlg SIZE 800, 600

@ 0, 0 IMAGE oImg FILENAME cWorkfile OF oDlg ;
SIZE nPWidth, nPHeight PIXEL NOBORDER ADJUST   

@ 20, 350 BUTTON oBtn1 PROMPT "
Draw" OF oDlg SIZE 40, 12 ;
ACTION DRAWIMG( oImg, hDC ) PIXEL

@ 50, 350 BUTTON oBtn2 PROMPT "
Save"OF oDlg SIZE 40, 12 ;
ACTION oImg:SaveImage( c_path1 + "
MYIMAGETEST.JPG", 2 )  PIXEL

@ 80, 350 BUTTON oBtn3 PROMPT "
Show" OF oDlg SIZE 40, 12 ;
ACTION SHOWEXPORT(oDlg, c_path1 + "
MYIMAGETEST.JPG", nPWidth, nPHeight )  PIXEL

@ 120, 350 SAY oSay1 PROMPT '% from original' SIZE 50,10 PIXEL FONT oFont1 OF oDlg
oSay1:Setcolor( 255,  )
oSay1:lTransparent := .T.

n := 10
FOR I := 1 TO 30
    AADD( aSize, { ALLTRIM(STR( n )) + "
%",  n } )
    n := n + 5
NEXT

@ 130, 350 COMBOBOX oCbx1 VAR cResize ITEMS { aSize[1][1], aSize[2][1], aSize[3][1], ;
     aSize[4][1], aSize[5][1], aSize[6][1], ;
     aSize[7][1], aSize[8][1], aSize[9][1], ;
     aSize[10][1], aSize[11][1], aSize[12][1], ;
     aSize[13][1], aSize[14][1], aSize[15][1], ;
     aSize[16][1], aSize[17][1], aSize[18][1], ;
     aSize[19][1], aSize[20][1], aSize[21][1], ;
    aSize[22][1], aSize[23][1], aSize[24][1], ;
    aSize[25][1], aSize[26][1], aSize[27][1], ;
    aSize[28][1], aSize[29][1], aSize[30][1] } ;
SIZE 42, 150 OF oDlg  PIXEL FONT oFont1 ;
ON CHANGE ( nResize := aSize[oCbx1:nAt][2] + 4, ;
                    nPWidth := nOWidth * ( nResize / 100 ), ;
                nPHeight := nOHeight * ( nResize / 100 ), ;
                IIF( nPWidth < oDlg:nWidth - 40 .and. nPWidth < oDlg:nHeight - 10, ;
                                   oImg:Move( 0, 0, nOWidth * ( nResize / 100 ), nOHeight * ( nResize / 100 ), .f. ), ;
                   MsgAlert( "
Preview is oversized !!!", "Error" ) ), ;
                oDlg:Refresh(), oImg:Refresh() )

@ 270, 350 BUTTON oBtn3 PROMPT "
Exit" OF oDlg SIZE 40, 12 ;
ACTION oDlg:End()  PIXEL

ACTIVATE DIALOG oDlg CENTER ;
ON INIT  hDC := oImg:GetDC()

oFont1:End()

RETURN NIL

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

STATIC FUNCTION DRAWIMG( oImg, hDC )
//LOCAL hDC := oImg:GetDC()

LOCAL nWidth  := oImg:nWidth()
LOCAL nHeight := oImg:nHeight()
LOCAL hMemDC := CREATECOMPATIBLEDC( hDC )
LOCAL hMemBmp := CREATECOMPATIBLEBITMAP( hDC, nWidth, nHeight )
LOCAL hBmpOld := SELECTOBJECT( hMemDC, hMemBmp )
LOCAL hBitmap  := oImg:hBitmap
LOCAL hPalette := oImg:hPalette

PALBMPDRAW( hMemDC, 0, 0, hBitmap, hPalette, nWidth, nHeight )

DO_CALC( hMemDC )

SELECTOBJECT( hMemDC, hBmpOld )
DELETEDC( hMemDC )
oImg:hBitmap = hMemBmp
PALBMPFREE( hBitmap, hPalette )
PALBMPNEW( oImg:hWnd, oImg:hBitmap, oImg:hPalette )
oImg:Refresh()

RETURN NIL

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

STATIC FUNCTION DO_CALC( hMemDC )
LOCAL x, y

FOR y = 0 TO 99
    FOR x = 0 TO 159
        SETPIXEL( hMemDC, x, y, CLR_HRED )
        NEXT
NEXT

RETURN NIL

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

STATIC FUNCTION SHOWEXPORT(oDlg, cDestFile, nPWidth, nPHeight)
LOCAL oDlg1, oTest, oBtn1

DEFINE DIALOG oDlg1 SIZE 800, 600  ;
TITLE c_path1 + "
MYIMAGETEST.JPG" OF oDlg

@ 0, 0 IMAGE oTest SIZE 390, 260 OF oDlg1 SCROLL
oTest:Progress( .f. )
oTest:LoadBmp( c_path1 + "
MYIMAGETEST.JPG" )

@ 270, 350 BUTTON oBtn1 PROMPT "
Exit" OF oDlg1 SIZE 40, 12 ;
ACTION oDlg1:End()  PIXEL

ACTIVATE DIALOG oDlg1 CENTER  

oTest:End()

RETURN( NIL )


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: Drawing on a TImage and save (revamped) :-)

Postby Enrico Maria Giordano » Sat Apr 05, 2014 6:38 pm

Uwe,

sorry, but your sample works exactly like mine. Try with a big image and

Code: Select all  Expand view
FOR y = 0 TO 1000
    FOR x = 0 TO 1000


The result is only shown ad the end of drawing not while drawing takes place. :-(

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Drawing on a TImage and save (revamped) :-)

Postby ukoenig » Sat Apr 05, 2014 6:56 pm

Enrico,
maybe Cou compiled the wrong file ?
Here it works perfect ( tested with 1024 x 768 )
like You can see in the screenshot with the different sizes of Your painting.
I still want to add a FILECHANGE-solution at runtime.

the complete files
once You have painted, You can resize with the combobox
Your painting will be resized as well related to the imagesize.
Resizing, you will get a warning reaching the maximum painting area-size.

Download :

http://www.pflegeplus.com/fw_downloads/Enrico1.zip

Image

added RUNTIME-change of images and dialog-title
with the size of the original image
(
will be included in next download )

Image

Best regards
Uwe :lol:
Last edited by ukoenig on Sat Apr 05, 2014 9:22 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: Drawing on a TImage and save (revamped) :-)

Postby Enrico Maria Giordano » Sat Apr 05, 2014 8:48 pm

Uwe, you paint an area that is too small. Try to paint an area of 1000 x 1000 and you will see the problem. I repeat what the problem is: I'd like to see the painted area gradually growing during the paint operation.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Drawing on a TImage and save (revamped) :-)

Postby ukoenig » Sat Apr 05, 2014 9:24 pm

Enrico,

I used the maximum possible painting-area
with my used screenresolution of 1024 x 768
I coudn't find any problem.

Do You want allways using the max painting area,
keeping the aspect ratio of the image ?

Image

best regards
Uwe :?:
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: Drawing on a TImage and save (revamped) :-)

Postby cnavarro » Sat Apr 05, 2014 9:40 pm

Enrico Maria Giordano wrote:Uwe, you paint an area that is too small. Try to paint an area of 1000 x 1000 and you will see the problem. I repeat what the problem is: I'd like to see the painted area gradually growing during the paint operation.

EMG

Enrico
Si lo he entendido bien

If I understand correctly

Code: Select all  Expand view


Function DrawOver( oImg )
Local x
Local y
For x = 10 to 50
   //For y = 10 to 50
       DrawImg( oImg, x )
       SysWait( 0.009 )      
   //Next y
Next x
Return Nil


// Function Actual de Enrico
STATIC FUNCTION DRAWIMG( oImg, y )

    LOCAL hDC := oImg:GetDC()

    LOCAL nWidth  := oImg:nWidth()
    LOCAL nHeight := oImg:nHeight()

    LOCAL hMemDC := CREATECOMPATIBLEDC( hDC )

    LOCAL hMemBmp := CREATECOMPATIBLEBITMAP( hDC, nWidth, nHeight )

    LOCAL hBmpOld := SELECTOBJECT( hMemDC, hMemBmp )

    LOCAL hBitmap  := oImg:hBitmap
    LOCAL hPalette := oImg:hPalette

    //LOCAL x, y
    Local x

    PALBMPDRAW( hMemDC, 0, 0, hBitmap, hPalette, nWidth, nHeight )

    //FOR y = 10 TO 50
        FOR x = 10 TO 50
            SETPIXEL( hMemDC, x, y, CLR_HRED )
            SysWait( 0.005 )
        NEXT
    //NEXT

    SELECTOBJECT( hMemDC, hBmpOld )

    DELETEDC( hMemDC )

    oImg:hBitmap = hMemBmp

    PALBMPFREE( hBitmap, hPalette )

    PALBMPNEW( oImg:hWnd, oImg:hBitmap, oImg:hPalette )

    oImg:Refresh()

    RETURN NIL
//-----------------------------------------------------------------------------
 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6501
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Drawing on a TImage and save (revamped) :-)

Postby Enrico Maria Giordano » Sat Apr 05, 2014 9:52 pm

Uwe,

ukoenig wrote:Enrico,

I used the maximum possible painting-area
with my used screenresolution of 1024 x 768
I coudn't find any problem.


Please try with:

Code: Select all  Expand view
STATIC FUNCTION DO_CALC( hMemDC )
LOCAL x, y

FOR y = 0 TO 1000
    FOR x = 0 TO 1000
        SETPIXEL( hMemDC, x, y, CLR_HRED )
        NEXT
NEXT

RETURN NIL


Sorry, I don't know how to explain the problem better.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Drawing on a TImage and save (revamped) :-)

Postby Enrico Maria Giordano » Sat Apr 05, 2014 9:54 pm

Cristobal,

cnavarro wrote:
Code: Select all  Expand view


Function DrawOver( oImg )
Local x
Local y
For x = 10 to 50
   //For y = 10 to 50
       DrawImg( oImg, x )
       SysWait( 0.009 )      
   //Next y
Next x
Return Nil


This would unacceptably slow the paint down, sorry. :-(

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: richard-service and 36 guests