FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Drawing on a TImage and save (revamped) :-) [Solved]
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Drawing on a TImage and save (revamped) :-)
Posted: Sat Apr 05, 2014 09:55 PM

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

EMG

Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Drawing on a TImage and save (revamped) :-)
Posted: Sat Apr 05, 2014 10:02 PM

Tried. As I suspected. Too slow. :-(

EMG

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Drawing on a TImage and save (revamped) :-)
Posted: Sat Apr 05, 2014 10:08 PM

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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Drawing on a TImage and save (revamped) :-)
Posted: Sat Apr 05, 2014 10:20 PM

Too slow. :-(

EMG

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Drawing on a TImage and save (revamped) :-)
Posted: Sat Apr 05, 2014 10:34 PM
Enrico Maria Giordano wrote:Too slow. :-)

EMG

Has probado con lineas enteras?

Have you tried with whole lines?

Code (fw): Select all Collapse
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
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Drawing on a TImage and save (revamped) :-)
Posted: Sun Apr 06, 2014 12:27 AM
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 :-)
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.
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Drawing on a TImage and save (revamped) :-)
Posted: Sun Apr 06, 2014 07:45 AM
Cristobal,

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

EMG

Has probado con lineas enteras?

Have you tried with whole lines?

Code (fw): Select all Collapse
LineTo( hDc,x,y )


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

EMG
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Drawing on a TImage and save (revamped) :-)
Posted: Sun Apr 06, 2014 07:57 AM

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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Drawing on a TImage and save (revamped) :-)
Posted: Sun Apr 06, 2014 09:41 AM
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 (fw): Select all Collapse
#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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Drawing on a TImage and save (revamped) :-)
Posted: Sun Apr 06, 2014 11:53 AM
Cristobal,

cnavarro wrote:
Code (fw): Select all Collapse
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
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Drawing on a TImage and save (revamped) :-) [Solved]
Posted: Mon Apr 07, 2014 03:30 PM
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 )





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



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



The DRAWIMG-function with the EMBEDDED styles :

Code (fw): Select all Collapse
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
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.
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Drawing on a TImage and save (revamped) :-) [Solved]
Posted: Mon Apr 07, 2014 04:54 PM

Uwe,

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

EMG

Continue the discussion