Page 3 of 3

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

PostPosted: Sat Apr 05, 2014 9:55 pm
by Enrico Maria Giordano
Or not? I'll make some experiment and let you know, thank you.

EMG

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

PostPosted: Sat Apr 05, 2014 10:02 pm
by Enrico Maria Giordano
Tried. As I suspected. Too slow. :-(

EMG

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

PostPosted: Sat Apr 05, 2014 10:08 pm
by cnavarro
Try removing the Drawimg syswait function
Put the syswait of DrawOver function in 0.0001
They are testing the processor?

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

PostPosted: Sat Apr 05, 2014 10:20 pm
by Enrico Maria Giordano
Too slow. :-(

EMG

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

PostPosted: Sat Apr 05, 2014 10:34 pm
by cnavarro
Enrico Maria Giordano wrote:Too slow. :-(

EMG

Has probado con lineas enteras?

Have you tried with whole lines?

Code: Select all  Expand view

LineTo( hDc,x,y )
 

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

PostPosted: Sun Apr 06, 2014 12:27 am
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:

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

PostPosted: Sun Apr 06, 2014 7:45 am
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 view

LineTo( hDc,x,y )
 


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

EMG

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

PostPosted: Sun Apr 06, 2014 7:57 am
by cnavarro
Ahhhh!, Ok
If you explain a little more, I can try to help

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

PostPosted: Sun Apr 06, 2014 9:41 am
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 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 "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

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

PostPosted: Sun Apr 06, 2014 11:53 am
by Enrico Maria Giordano
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


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

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

PostPosted: Mon Apr 07, 2014 3:30 pm
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 view

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
 

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

PostPosted: Mon Apr 07, 2014 4:54 pm
by Enrico Maria Giordano
Uwe,

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

EMG