FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Drawing on a TImage and save [Solved]
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Drawing on a TImage and save [Solved]
Posted: Sun Mar 30, 2014 06:13 PM
Dear friends, I need to draw on a TImage control and save the result. I already tried using SetPixel() on TImage hDC but it saves the original image without my new drawings. This is a sample:

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

聽 聽 LOCAL oDlg, oImg

聽 聽 DEFINE DIALOG oDlg;
聽 聽 聽 聽 聽 聽SIZE 800, 600

聽 聽 @ 0, 0 IMAGE oImg;
聽 聽 聽 聽 聽 聽FILE "TEST.JPG"

聽 聽 @ 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 x, y

聽 聽 FOR y = 10 TO 50
聽 聽 聽 聽 FOR x = 10 TO 50
聽 聽 聽 聽 聽 聽 SETPIXEL( hDC, x, y, CLR_HRED )
聽 聽 聽 聽 NEXT
聽 聽 NEXT

聽 聽 oImg:ReleaseDC()

聽 聽 RETURN NIL


Any ideas?

Thank you in advance.

EMG
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Drawing on a TImage and save
Posted: Sun Mar 30, 2014 09:33 PM
Enrico
I understand what you're trying, but I have not found a simple way
I used a function of Daniel Garcia-Gil found in this forum but I make the bitmap in black
I modified the function found in Microsoft MSDN and running, but my knowledge does not allow me to save the file as JPG and BMP only as

Entiendo lo que intentas, pero no he encontrado una forma sencilla
He usado una function de Daniel Garcia-Gil encontrada en este foro pero me crea el bitmap en negro
He modificado la function encontrada en el MSDN de Microsoft y funciona correctamente, pero mis conocimientos no me permiten guardar el fichero como JPG y solo como BMP

Code (fw): Select all Collapse
#include "Fivewin.ch"

#define SRCCOPY 聽 聽 聽 聽 聽0x00CC0020
#define SM_CXSCREEN 聽 聽 聽0 
#define SM_CYSCREEN 聽 聽 聽1

#define HALFTONE 聽4

FUNCTION MAIN()

聽 聽 LOCAL oDlg, oImg

聽 聽 DEFINE DIALOG oDlg;
聽 聽 聽 聽 聽 聽SIZE 800, 600

聽 聽 @ 0, 0 IMAGE oImg;
聽 聽 聽 聽 聽 聽FILE "WORD.JPG" OF oDlg

聽 聽 @ 15, 5 BUTTON "Draw";
聽 聽 聽 聽 聽 聽 ACTION ( DRAWIMG( oImg ) ) //, oImg:Refresh() )
聽 聽 聽 聽 聽 聽 
聽 聽 @ 15, 25 BUTTON "Save FW";
聽 聽 聽 聽 聽 聽 聽ACTION SaveMiBmp( oDlg, oImg:nTop, oImg:nLeft, ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽oImg:nWidth, oImg:nHeight, "IMAGENFW.BMP" ) //.JPG" )
聽 聽 聽 聽 聽 聽 //ACTION oImg:SaveImage( "IMGENFW.JPG", 2 )


聽 聽 @ 15, 40 BUTTON "Save C";
聽 聽 聽 聽 聽 聽 聽ACTION CaptureImage( oDlg:hWnd, oImg:nTop, oImg:nLeft, ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 oImg:nWidth, oImg:nHeight, "IMAGENC.BMP" )

聽 聽 @ 15, 55 BUTTON "Exit" ACTION oDlg:End()

聽 聽 ACTIVATE DIALOG oDlg;
聽 聽 聽 聽 聽 聽 聽CENTER 

聽 聽 RETURN NIL


STATIC FUNCTION DRAWIMG( oImg )

聽 聽 LOCAL hDC := oImg:GetDC()
聽 聽 Local uImg

聽 聽 LOCAL x, y

聽 聽 FOR y = 10 TO 50
聽 聽 聽 聽 FOR x = 10 TO 50
聽 聽 聽 聽 聽 聽 SETPIXEL( hDC, x, y, CLR_HRED )
聽 聽 聽 聽 NEXT
聽 聽 NEXT

聽 聽 oImg:ReleaseDC()
RETURN uImg

//-----------------------------------------------------------------------------
//http://forums.fivetechsupport.com/viewtopic.php?f=6&t=19403&p=137661&hilit=SaveToBmp#p102241
// SaveToBmp2 de Daniel Garcia-Gil con modificaciones
// Cristobal Navarro
//-----------------------------------------------------------------------------

Function SaveMiBmp( oWnd, nTop, nLeft, nWidth, nHeight, cBmpFile )

聽 聽local hParDC 聽 := oWnd:GetDC()
聽 聽local hBmp
聽 聽local hOldBmp
聽 聽local hDib
聽 聽local hDC 聽 聽 聽:= CreateCompatibleDC( hParDC )

聽 聽 //This is the best stretch mode
聽 聽 SetStretchBltMode(hParDC,HALFTONE)

聽 聽 //The source DC is the entire screen and the destination DC is the current window (HWND)
聽 聽 StretchBlt(hParDC,; 
聽 聽 聽 聽 聽 聽 聽 聽0,0,; 
聽 聽 聽 聽 聽 聽 聽 聽nWidth, nHeight,; 
聽 聽 聽 聽 聽 聽 聽 聽hDC,; 
聽 聽 聽 聽 聽 聽 聽 聽0,0,;
聽 聽 聽 聽 聽 聽 聽 聽GetSysMetrics( nWidth - nLeft ),; 聽//GetSystemMetrics (SM_CXSCREEN),
聽 聽 聽 聽 聽 聽 聽 聽GetSysMetrics( nHeight - nTop ),; 聽//GetSystemMetrics (SM_CYSCREEN),
聽 聽 聽 聽 聽 聽 聽 聽SRCCOPY)

聽 聽hBmp 聽 聽 聽:= CreateCompatibleBitmap( hDC, nWidth, nHeight )
聽 聽hOldBmp 聽 := SelectObject( hDC, hBmp )

聽 聽BitBlt( hDC, 0, 0, nWidth, nHeight, hParDC, 0, 0, SRCCOPY )

聽 聽SelectObject( hDC, hOldBmp )
聽 聽DeleteDC( hDC )
聽 聽hDib = DibFromBitmap( hBmp )
聽 聽DibWrite( cBmpFile, hDib )
聽 聽GloBalFree( hDib )
聽 聽DeleteObject( hBmp )
聽 聽oWnd:ReleaseDC() 聽 

Return ( File( cBmpFile ) )

//-----------------------------------------------------------------------------
// Daniel Garcia - Gil 聽- 聽Original
//http://forums.fivetechsupport.com/viewtopic.php?f=6&t=19403&p=137661&hilit=SaveToBmp#p102241
//-----------------------------------------------------------------------------

Function SaveToBmp2( oWnd, cBmpFile )
聽 聽
聽 聽local hDeskDC := GetDC( GetDesktopWindow() )
聽 聽local hDC 聽:= CreateCompatibleDC( hDeskDC )
聽 聽local hOldBmp
聽 聽local hDib 
聽 聽local hBmp
聽 聽local nWidth //:= GetSysMetrics( SM_CXSCREEN )
聽 聽local nHeight //:= GetSysMetrics( SM_CYSCREEN )
聽 聽
聽 聽 聽 
聽 聽hBmp = CreateCompatibleBitmap( hDeskDC, nWidth, nHeight )

聽 聽hOldBmp = SelectObject( hDC, hBmp )
聽 聽
聽 聽// No // PrintWindow( oWnd:hWnd, hDC )
聽 聽
聽 聽BitBlt( hDC, 0, 0, nWidth, nHeight, hDeskDC, 0, 0, SRCCOPY )
聽 聽
聽 聽SelectObject( hDC, hOldBmp )
聽 聽DeleteDC( hDC )
聽 聽hDib = DibFromBitmap( hBmp )
聽 聽DibWrite( cBmpFile, hDib )
聽 聽GloBalFree( hDib )
聽 聽DeleteObject( hBmp )

return ( File( cBmpFile ) )
聽
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

#pragma BEGINDUMP

//#define STRICT
#include "stdafx.h"
#include "windows.h"
#include "hbapi.h"

//-----------------------------------------------------------------------------
//http://msdn.microsoft.com/en-us/library/windows/desktop/dd183402(v=vs.85).aspx
// Modificada por Cristobal Navarro
//-----------------------------------------------------------------------------

int CaptureAnImage(HWND hWnd,
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽int nTop, int nLeft, 聽
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽int nW , int nH , LPCTSTR pszFichero )
{
聽 聽 HDC hdcScreen;
聽 聽 HDC hdcWindow;
聽 聽 HDC hdcMemDC = NULL;
聽 聽 HBITMAP hbmScreen = NULL;
聽 聽 BITMAP bmpScreen;

聽 聽 // Retrieve the handle to a display device context for the client 
聽 聽 // area of the window. 
聽 聽 hdcScreen = GetDC(NULL);
聽 聽 hdcWindow = GetDC(hWnd);

聽 聽 // Create a compatible DC which is used in a BitBlt from the window DC
聽 聽 hdcMemDC = CreateCompatibleDC(hdcWindow); 

聽 聽 if(!hdcMemDC)
聽 聽 {
聽 聽 聽 聽 MessageBox(hWnd, TEXT("CreateCompatibleDC has failed"), TEXT("Failed"), MB_OK);
聽 聽 聽 聽 goto done;
聽 聽 }

聽 聽 // Get the client area for size calculation
聽 聽 RECT rcClient;
聽 聽 rcClient.top = nTop; //0;
聽 聽 聽 聽 rcClient.left = nLeft; //0;
聽 聽 聽 聽 rcClient.right = nW; //200;
聽 聽 聽 聽 rcClient.bottom = nH; //100;

聽 聽 //GetWindowRect(hWnd, &rcClient );
聽 聽 //GetClientRect(hWnd, &rcClient );

聽 聽 //This is the best stretch mode
聽 聽 SetStretchBltMode(hdcWindow,HALFTONE);

聽 聽 //The source DC is the entire screen and the destination DC is the current window (HWND)
聽 聽 if(!StretchBlt(hdcWindow, 
聽 聽 聽 聽 聽 聽 聽 聽0,0, 
聽 聽 聽 聽 聽 聽 聽 聽rcClient.right, rcClient.bottom, 
聽 聽 聽 聽 聽 聽 聽 聽hdcScreen, 
聽 聽 聽 聽 聽 聽 聽 聽0,0,
聽 聽 聽 聽 聽 聽 聽 聽GetSystemMetrics( rcClient.right - rcClient.left ), 聽//GetSystemMetrics (SM_CXSCREEN),
聽 聽 聽 聽 聽 聽 聽 聽GetSystemMetrics( rcClient.bottom - rcClient.top ), 聽//GetSystemMetrics (SM_CYSCREEN),
聽 聽 聽 聽 聽 聽 聽 聽SRCCOPY))
聽 聽 {
聽 聽 聽 聽 MessageBox(hWnd, TEXT("StretchBlt has failed"),TEXT("Failed"), MB_OK);
聽 聽 聽 聽 goto done;
聽 聽 }
聽 聽 
聽 聽 // Create a compatible bitmap from the Window DC
聽 聽 hbmScreen = CreateCompatibleBitmap(hdcWindow, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top);
聽 聽 
聽 聽 if(!hbmScreen)
聽 聽 {
聽 聽 聽 聽 MessageBox(hWnd, TEXT("CreateCompatibleBitmap Failed"),TEXT("Failed"), MB_OK);
聽 聽 聽 聽 goto done;
聽 聽 }

聽 聽 // Select the compatible bitmap into the compatible memory DC.
聽 聽 SelectObject(hdcMemDC,hbmScreen);
聽 聽 
聽 聽 // Bit block transfer into our compatible memory DC.
聽 聽 if(!BitBlt(hdcMemDC, 
聽 聽 聽 聽 聽 聽 聽 聽0,0, 
聽 聽 聽 聽 聽 聽 聽 聽rcClient.right-rcClient.left, 
聽 聽 聽 聽 聽 聽 聽 聽rcClient.bottom-rcClient.top, 
聽 聽 聽 聽 聽 聽 聽 聽hdcWindow, 
聽 聽 聽 聽 聽 聽 聽 聽0,0,
聽 聽 聽 聽 聽 聽 聽 聽SRCCOPY))
聽 聽 {
聽 聽 聽 聽 MessageBox(hWnd, TEXT("BitBlt has failed"), TEXT("Failed"), MB_OK);
聽 聽 聽 聽 goto done;
聽 聽 }

聽 聽 // Get the BITMAP from the HBITMAP
聽 聽 GetObject(hbmScreen,sizeof(BITMAP),&bmpScreen);
聽 聽 聽
聽 聽 BITMAPFILEHEADER 聽 bmfHeader; 聽 聽
聽 聽 BITMAPINFOHEADER 聽 bi;
聽 聽 聽
聽 聽 bi.biSize = sizeof(BITMAPINFOHEADER); 聽 聽
聽 聽 bi.biWidth = bmpScreen.bmWidth; 聽 聽
聽 聽 bi.biHeight = bmpScreen.bmHeight; 聽
聽 聽 bi.biPlanes = 1; 聽 聽
聽 聽 bi.biBitCount = 32; 聽 聽
聽 聽 bi.biCompression = BI_RGB; 聽 聽
聽 聽 bi.biSizeImage = 0; 聽
聽 聽 bi.biXPelsPerMeter = 0; 聽 聽
聽 聽 bi.biYPelsPerMeter = 0; 聽 聽
聽 聽 bi.biClrUsed = 0; 聽 聽
聽 聽 bi.biClrImportant = 0;

聽 聽 DWORD dwBmpSize = ((bmpScreen.bmWidth * bi.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight;

聽 聽 // Starting with 32-bit Windows, GlobalAlloc and LocalAlloc are implemented as wrapper functions that 
聽 聽 // call HeapAlloc using a handle to the process's default heap. Therefore, GlobalAlloc and LocalAlloc 
聽 聽 // have greater overhead than HeapAlloc.
聽 聽 HANDLE hDIB = GlobalAlloc(GHND,dwBmpSize); 
聽 聽 char *lpbitmap = (char *)GlobalLock(hDIB); 聽 聽

聽 聽 // Gets the "bits" from the bitmap and copies them into a buffer 
聽 聽 // which is pointed to by lpbitmap.
聽 聽 GetDIBits(hdcWindow, hbmScreen, 0,
聽 聽 聽 聽 (UINT)bmpScreen.bmHeight,
聽 聽 聽 聽 lpbitmap,
聽 聽 聽 聽 (BITMAPINFO *)&bi, DIB_RGB_COLORS);

聽 聽 // A file is created, this is where we will save the screen capture.
聽 聽 HANDLE hFile = CreateFile( pszFichero , //TEXT("capture.bmp"),
聽 聽 聽 聽 GENERIC_WRITE,
聽 聽 聽 聽 0,
聽 聽 聽 聽 NULL,
聽 聽 聽 聽 CREATE_ALWAYS,
聽 聽 聽 聽 FILE_ATTRIBUTE_NORMAL, NULL); 聽 
聽 聽 
聽 聽 // Add the size of the headers to the size of the bitmap to get the total file size
聽 聽 DWORD dwSizeofDIB = dwBmpSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
聽
聽 聽 //Offset to where the actual bitmap bits start.
聽 聽 bmfHeader.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER); 
聽 聽 
聽 聽 //Size of the file
聽 聽 bmfHeader.bfSize = dwSizeofDIB; 
聽 聽 
聽 聽 //bfType must always be BM for Bitmaps
聽 聽 bmfHeader.bfType = 0x4D42; //BM 聽 
聽
聽 聽 DWORD dwBytesWritten = 0;
聽 聽 WriteFile(hFile, (LPSTR)&bmfHeader, sizeof(BITMAPFILEHEADER), &dwBytesWritten, NULL);
聽 聽 WriteFile(hFile, (LPSTR)&bi, sizeof(BITMAPINFOHEADER), &dwBytesWritten, NULL);
聽 聽 WriteFile(hFile, (LPSTR)lpbitmap, dwBmpSize, &dwBytesWritten, NULL);
聽 聽 
聽 聽 //Unlock and Free the DIB from the heap
聽 聽 GlobalUnlock(hDIB); 聽 聽
聽 聽 GlobalFree(hDIB);

聽 聽 //Close the handle for the file that was created
聽 聽 CloseHandle(hFile);
聽 聽 聽 聽
聽 聽 //Clean up
done:
聽 聽 DeleteObject(hbmScreen);
聽 聽 DeleteObject(hdcMemDC);
聽 聽 ReleaseDC(NULL,hdcScreen);
聽 聽 ReleaseDC(hWnd,hdcWindow);

聽 聽 return 0;
}


HB_FUNC( CAPTUREIMAGE )
{
聽 CaptureAnImage( (HWND) hb_parnl( 1 ), hb_parnl( 2 ), hb_parnl( 3 ), 
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽hb_parnl( 4 ), hb_parnl( 5 ), hb_parc( 6 ) ) ;
}


#pragma ENDDUMP
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
Posted: Sun Mar 30, 2014 09:45 PM
Cristobal,

cnavarro wrote:Enrico
I understand what you're trying, but I have not found a simple way


I can't compile your sample, sorry. I'm searching for an easier way... :-)

EMG
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Drawing on a TImage and save
Posted: Sun Mar 30, 2014 09:46 PM

This tested with VS2012

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
Posted: Sun Mar 30, 2014 09:48 PM
Cristobal,

cnavarro wrote:This tested with VS2012


I'm using BCC581. Thank you anyway.

EMG
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Drawing on a TImage and save
Posted: Sun Mar 30, 2014 09:50 PM

If you want to try it put an image is called word.jpg

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: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Drawing on a TImage and save
Posted: Sun Mar 30, 2014 09:53 PM

I'll try to compile with BCC582

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
Posted: Sun Mar 30, 2014 10:12 PM
Cristobal,

cnavarro wrote:https://www.dropbox.com/s/kwk4hd470beg5j8/IMAGEN.zip

If you want to try it put an image is called word.jpg


Thank you. Unfortunately, the image is out of alignment (ie. is slightly shifted).

EMG
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Drawing on a TImage and save
Posted: Sun Mar 30, 2014 10:12 PM
Cristobal,

cnavarro wrote:I'll try to compile with BCC582


Thank you.

EMG
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Drawing on a TImage and save
Posted: Mon Mar 31, 2014 12:06 PM
Enrico,
my first drawing-tests.

Do You want to paint freehand or lines ?
Maybe do You want also saving a RESIZED-result of the original ?

Drawing :


Result of the saved image with a external image-editor :



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
Posted: Mon Mar 31, 2014 12:11 PM
Uwe,

ukoenig wrote:Enrico,
my first tests.


Thank you.

ukoenig wrote:Do You want to paint freehand or lines ?


Lines. I'm doing some experiment too. I'd like to assign the new bitmap to the TImage control. It seems you have to play with hDCs (CreateCompatible...).

EMG
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Drawing on a TImage and save
Posted: Mon Mar 31, 2014 12:48 PM
Solved!

Edit: not solved yet as drawing on the stretched image is not the same as drawing on the original one. :-)

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;
聽 聽 聽 聽 聽 聽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 x, y

聽 聽 FOR y = 10 TO 50
聽 聽 聽 聽 FOR x = 10 TO 50
聽 聽 聽 聽 聽 聽 SETPIXEL( hDC, x, y, CLR_HRED )
聽 聽 聽 聽 NEXT
聽 聽 NEXT

聽 聽 UPDATEIMG( oImg, hDC )

聽 聽 oImg:ReleaseDC()

聽 聽 RETURN NIL


STATIC FUNCTION UPDATEIMG( oImg, hDC )

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

聽 聽 LOCAL hMemDC := CREATECOMPATIBLEDC( hDC )

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

聽 聽 LOCAL hBmpOld := SELECTOBJECT( hMemDC, hMemBmp )

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

聽 聽 BITBLT( hMemDC, 0, 0, nWidth, nHeight, hDC, 0, 0, SRCCOPY )

聽 聽 SELECTOBJECT( hMemDC, hBmpOld )

聽 聽 DELETEDC( hMemDC )

聽 聽 oImg:hBitmap = hMemBmp

聽 聽 PALBMPFREE( hBitmap, hPalette )

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

聽 聽 RETURN NIL


EMG
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Drawing on a TImage and save [Solved]
Posted: Mon Mar 31, 2014 01:39 PM
I added some options :

1. The dialog is adjusted to the image-size.

2. change LINESTYLE ( change from FREEHAND to LINES )
selecting lines : first click = startposition, second click = line-end.

3. change at runtime PEN-size and color

still have to add, moving a line



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 [Solved]
Posted: Mon Mar 31, 2014 01:42 PM

Uwe,

you're a war-machine with your sample! :-)

EMG

Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Drawing on a TImage and save [Solved]
Posted: Mon Mar 31, 2014 06:06 PM
Enrico,

it is really fun, working with it.
do we still need to paint on a RESIZED image ?
added image-change and showing the used Pensize inside the combobox, You are drawing with.
A new selected image is adjusted inside the dialog with the new size.
Some more options will follow, like to define the EXPORT-image-name.

free painting on a image with different colors and pensizes
poor Olga :-)



The external Editor-preview of the saved result
We could do this from inside the program with a extra dialog.



Added RESIZE and save to INI



Added PREVIEW of the RESIZED EXPORT-image :
I think it is completed now ? or still something missing ?



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.