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

User avatar
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

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

Post by Enrico Maria Giordano »

Or not? I'll make some experiment and let you know, thank you.

EMG
User avatar
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

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

Post by cnavarro »

Try removing the Drawimg syswait function
Put the syswait of DrawOver function in 0.0001
They are testing the processor?
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: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

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

Post by cnavarro »

Enrico Maria Giordano wrote:Too slow. :-(

EMG

Has probado con lineas enteras?

Have you tried with whole lines?

Code: Select all | Expand


LineTo( hDc,x,y )
 
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
ukoenig
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

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

Post by ukoenig »

Define on top :

nPensize := 50
nPenColor := 255

hPen := CreatePen( 0, nPensize, nPenColor )


// -----

STATIC FUNCTION DRAWIMG( oImg, hDC, hPen, nPensize, nPenColor )
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_LINES( hMemDC, hPen, nPensize, nPenColor )

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_LINES( hMemDC, hPen, nPensize, nPenColor )
LOCAL aPoints[2][2], hOldPen

aPoints[1] := { 100, 200 } // Start x, y
aPoints[2] := { 100, 400 } // End x, y

hOldPen := SelectObject( hMemDC, hPen )

MoveTo( hMemDC, aPoints[ 1, 2 ], aPoints[ 1, 1 ] )
LineTo( hMemDC, aPoints[ 2, 2 ], aPoints[ 2, 1 ] )

hOldPen := SelectObject( hMemDC, hPen )

SelectObject( hMemDC, hOldPen )

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
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

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

Post by Enrico Maria Giordano »

Cristobal,

cnavarro wrote:
Enrico Maria Giordano wrote:Too slow. :-(

EMG

Has probado con lineas enteras?

Have you tried with whole lines?

Code: Select all | Expand


LineTo( hDc,x,y )
 


This is only a sample. I must process the image with complex algorithms not with point or lines.

EMG
User avatar
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

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

Post by cnavarro »

Ahhhh!, Ok
If you explain a little more, I can try to help
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
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

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

Post by Enrico Maria Giordano »

Cristobal,

I really don't know how to explain it better than a sample. I'd like to see the processing while it takes place, not all at a time at the end. This is the sample. Please use an image bigger than 1000 x 1000.

Code: Select all | Expand

#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 "TEST.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 999
        FOR x = 0 TO 999
            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: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

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

Post by Enrico Maria Giordano »

Cristobal,

cnavarro wrote:

Code: Select all | Expand



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


Your idea is not that bad in the end! I simply call DrawImg() less times and then the speed is very good now!

Thank you to you and Uwe for the valuable ideas!

EMG
User avatar
ukoenig
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

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

Post by ukoenig »

Enrico,

You don't need to call DRAWIMG( inside Your drawing function !
I added 10 different painting-styles and now
I can draw and merge everything I want to do with the image and export to a different format.
The styles are defined INSIDE DRAWIMG(.... !!!
I'm using a maximum of a drawing area. The image is adjusted to this size and keeps the aspect ratio !!!

Drawing-sStyles :

Calculated Lines
Calculated Pixel
Calculated Box
Calculated Fill
Freehand
Click Lines
Click Box
Click Fill
Image
Transp. Logo


Sample : I added a transparent logo ( can be a WATERMARK, changing the transparent level )

Image

Image

Oversized image ( adjusted to the paint-area ) with a merged second image

Image

A preview of the exported image with the original size. Image < SCROLL >

Image

The DRAWIMG-function with the EMBEDDED styles :

Code: Select all | Expand


STATIC FUNCTION DRAWIMG( oDrawImg, hDC, hPen, nPensize, nPenColor, cDrawStyle, c_Path1 )

LOCAL nWidth  := oDrawImg:nWidth()
LOCAL nHeight := oDrawImg:nHeight()
LOCAL hMemBmp, hBmpOld
LOCAL hBitmap  := oDrawImg:hBitmap
LOCAL hPalette := oDrawImg:hPalette

hMemDC := CREATECOMPATIBLEDC( hDC )
hMemBmp := CREATECOMPATIBLEBITMAP( hDC, nWidth, nHeight )
hBmpOld := SELECTOBJECT( hMemDC, hMemBmp )

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

// ------ STYLES -----------

IF cDrawStyle = "Calc Lines"
    DRAW_LINES( hMemDC, hPen, nPensize, nPenColor )
ENDIF
IF cDrawStyle = "Calc Pixel"
    DRAW_PIXEL( hMemDC, hPen, nPensize, nPenColor )
ENDIF
IF cDrawStyle = "Calc Box"
    DRAW_BOX( hMemDC, hPen, nPensize, nPenColor )
ENDIF
IF cDrawStyle = "Calc Fill"
    DRAW_FILL( hMemDC, hPen, nPensize, nPenColor )
ENDIF
IF cDrawStyle = "Freehand"
    DRAW_FREE( hMemDC, hPen, nPensize, nPenColor )
ENDIF
IF cDrawStyle = "Click Lines"
    CLICK_LINES( hMemDC, hPen, nPensize, nPenColor )
ENDIF
IF cDrawStyle = "Click Box"
    CLICK_BOX( hMemDC, hPen, nPensize, nPenColor )
ENDIF
IF cDrawStyle = "Click Fill"
    CLICK_FILL( hMemDC, hPen, nPensize, nPenColor )
ENDIF
IF cDrawStyle = "Image"
    DRAW_IMAGE( hMemDC, c_Path1 )
ENDIF
IF cDrawStyle = "Transp. Logo"
    DRAW_LOGO( hMemDC, c_Path1 )
ENDIF

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

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

oDrawImg:Refresh()

RETURN NIL
 
Last edited by ukoenig on Mon Apr 07, 2014 5:16 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
Enrico Maria Giordano
Posts: 8753
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 4 times
Contact:

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

Post by Enrico Maria Giordano »

Uwe,

sorry, you still haven't understood my problem. But it's solved for me. Thank you anyway.

EMG
Post Reply