Drawing on a TImage and save (revamped) :-) [Solved]
- 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) :-)
Uwe,
sorry, but I need to handle bigger images (3000 pixels).
EMG
sorry, but I need to handle bigger images (3000 pixels).
EMG
Re: Drawing on a TImage and save (revamped) :-)
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
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.
i work with FW.
If you have any questions about special functions, maybe i can help.
- 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) :-)
Uwe,
I need to draw programmatically. I can't use the scrollbar.
EMG
I need to draw programmatically. I can't use the scrollbar.
EMG
- 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) :-)
Maybe solved! 
EMG

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

Saved image 100 %

just working on a screen-adjustment

Best regards
Uwe
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

--------------------
--------------------
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 %

Saved image 100 %

just working on a screen-adjustment

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.
i work with FW.
If you have any questions about special functions, maybe i can help.
- 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) :-)
Uwe,
I don't understand. Can you build a compilable sample, please?
EMG
I don't understand. Can you build a compilable sample, please?
EMG
Re: Drawing on a TImage and save (revamped) :-)
Enrico,
completed with export-preview !
best regards
Uwe
completed with export-preview !
Code: Select all | Expand
#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

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.
i work with FW.
If you have any questions about special functions, maybe i can help.
- 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) :-)
Uwe,
sorry, but your sample works exactly like mine. Try with a big image and
The result is only shown ad the end of drawing not while drawing takes place.
EMG
sorry, but your sample works exactly like mine. Try with a big image and
Code: Select all | Expand
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
Re: Drawing on a TImage and save (revamped) :-)
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

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

Best regards
Uwe
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

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

Best regards
Uwe

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.
i work with FW.
If you have any questions about special functions, maybe i can help.
- 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) :-)
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
EMG
Re: Drawing on a TImage and save (revamped) :-)
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 ?

best regards
Uwe
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 ?

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.
i work with FW.
If you have any questions about special functions, maybe i can help.
Re: Drawing on a TImage and save (revamped) :-)
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
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
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
- 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) :-)
Uwe,
Please try with:
Sorry, I don't know how to explain the problem better.
EMG
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
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
- 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) :-)
Cristobal,
This would unacceptably slow the paint down, sorry.
EMG
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
This would unacceptably slow the paint down, sorry.

EMG