Save a bitmaphandle to file (jpg or png)
Re: Save a bitmaphandle to file (jpg or png)
Günther,
can You explain in detail ( maybe a sample ), what exactly You want to do ?
best regards
Uwe![Question :?:](./images/smilies/icon_question.gif)
can You explain in detail ( maybe a sample ), what exactly You want to do ?
best regards
Uwe
![Question :?:](./images/smilies/icon_question.gif)
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: Save a bitmaphandle to file (jpg or png)
Uwe, i make a compatible bitmap and draw some graphics in this. Now i will save the bitmap (hBmp) in a file jpg or png. But no Freeimage-functions!
Code: Select all | Expand
hDC := CreateCompatibleDC( oParent:GetDC() )
hBmp := CreateCompatibleBitMap( hDC, nRechts, nUnten )
hBmpOld := SelectObject( hDC, hBmp )
drawing_function(hDc,...)
SelectObject( hDC, hBmpOld )
DeleteDC( hDC )
DeleteObject( hBmpOld )
oParent:ReleaseDC()
return hBmp
- nageswaragunupudi
- Posts: 10721
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 8 times
- Contact:
Re: Save a bitmaphandle to file (jpg or png)
Please try this and let us know if it works:
Code: Select all | Expand
oImage := GdiBmp():New()
oImage:hBmp := GDIP_FromHBitmap( hBitmap,,HasAlpha( hBitmap ) )
oImage:Save( "filenamewithExt" ) // for jpg, add nQuality as 2nd param
oImage:End()
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- nageswaragunupudi
- Posts: 10721
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 8 times
- Contact:
Re: Save a bitmaphandle to file (jpg or png)
In addition, if you plan to have some bitmaps with your own owner-draw for use in FWH, please consider using the new Draw Shapes functionality we provided.
You can define any complex drawings consisting of Line(s), rectangles, polygons, ellipses, curves, closed and unclosed in the form of arrays. You can easily create bitmaps from these arrays or in some cases, you can even straight away use them in the place of bitmaps.
Please try this example. I suggest you build it and see.
Screen shot:
![Image](http://imagizer.imageshack.us/v2/xq90/923/pfAh5k.png)
For detailed documentation, please refer to whatsnew.txt January 2016.
Flexibility:
1. Enables drawing of all possible shapes
2. We can have library of different shapes and combine them to form different complex shapes as and when required.
3. Scalable at runtime. (Eg we can use the same Shape as a bitmap of 32x32 in one place and 128x128 in some other place without loss of quality)
3. Create AlphaBitmaps at runtime and use in place of regular bitmaps. Optionally save these bitmaps.
4. In some cases (btnbmp, buttonbmp, xbrowse) we can use the array of shapes directly even without creating a bitmap (avoiding the need to release the bitmap resource)
5. Save shapes or components of shapes as arrays in source code or as data.
You can define any complex drawings consisting of Line(s), rectangles, polygons, ellipses, curves, closed and unclosed in the form of arrays. You can easily create bitmaps from these arrays or in some cases, you can even straight away use them in the place of bitmaps.
Please try this example. I suggest you build it and see.
Code: Select all | Expand
function TestDraw()
local oDlg, oBtn, aMyDrawing
aMyDrawing := MyDrawing()
DEFINE DIALOG oDlg SIZE 300,200 PIXEL TRUEPIXEL
@ 40,100 BTNBMP SIZE 100,128 PIXEL OF oDlg ;
PROMPT "NATURE" BITMAP { 90, 90, aMyDrawing }
ACTIVATE DIALOG oDlg CENTERED
return nil
function MyDrawing()
local aDrawing
local aSky := { 'R', RGB( 111, 183, 255 ), 0, 64, 64, 0, 0, 63, 63 }
local aSun := { 'E', RGB( 254, 227, 167 ), 0, 64, 64, 7, 7, 55, 55 }
local aHill := { 'L', RGB( 187, 108, 85 ), 0, 64, 64, 63, 0, 52, 0, 42, 16, 52, 32, 40, 48, 60, 63, 63, 63 }
local aGrn := { 'L', RGB( 64, 128, 64 ), 0, 64, 64, 63, 0, 60, 0, 56, 20, 60, 32, 56, 48, 61, 63, 63, 63 }
local aBrd := { 'R', CLR_BLACK, 1, 64, 64, 0, 0, 63, 63 }
aDrawing := { aSky, aSun, aHill, aGrn, aBrd }
return aDrawing
Screen shot:
![Image](http://imagizer.imageshack.us/v2/xq90/923/pfAh5k.png)
For detailed documentation, please refer to whatsnew.txt January 2016.
Flexibility:
1. Enables drawing of all possible shapes
2. We can have library of different shapes and combine them to form different complex shapes as and when required.
3. Scalable at runtime. (Eg we can use the same Shape as a bitmap of 32x32 in one place and 128x128 in some other place without loss of quality)
3. Create AlphaBitmaps at runtime and use in place of regular bitmaps. Optionally save these bitmaps.
4. In some cases (btnbmp, buttonbmp, xbrowse) we can use the array of shapes directly even without creating a bitmap (avoiding the need to release the bitmap resource)
5. Save shapes or components of shapes as arrays in source code or as data.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: Save a bitmaphandle to file (jpg or png)
Mr. Rao,
there is a problem using GDIPLUS, because on window or dialog-resize
images are deleted. Silvio reported this problem as well.
Is there any solution to solve the problem ?
I created a sample changing and saving images using TImage
but FREEIMAGE.dll is needed ( Günther doesn't want to use it )
best regards
Uwe![Question :?:](./images/smilies/icon_question.gif)
there is a problem using GDIPLUS, because on window or dialog-resize
images are deleted. Silvio reported this problem as well.
Is there any solution to solve the problem ?
I created a sample changing and saving images using TImage
but FREEIMAGE.dll is needed ( Günther doesn't want to use it )
best regards
Uwe
![Question :?:](./images/smilies/icon_question.gif)
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.
- nageswaragunupudi
- Posts: 10721
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 8 times
- Contact:
Re: Save a bitmaphandle to file (jpg or png)
ukoenig wrote:Mr. Rao,
there is a problem using GDIPLUS, because on window or dialog-resize
images are deleted. Silvio reported this problem as well.
Is there any solution to solve the problem ?
best regards
Uwe
Problems are not with gdi+. Problems are with our usage.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: Save a bitmaphandle to file (jpg or png)
Mr. Rao,
for my tests I'm using the basics from sample GDIPLUS3.prg
where I noticed the same problem.
It belongs to the button-action
Tested ( Green = OK )
@28,4 button "rectangle" size 120,30 Action Drawrectangle(ownd)
@28,24 button "roundrect" size 120,30 Action ( oWnd:Refresh(), ;
oWnd:bPainted := {|| Drawroundrect(ownd) } )
@28,44 button "drawImage" size 120,30 Action DrawImage(ownd)
@28,64 button "drawEllipse" size 120,30 Action DrawEllipse(ownd)
@28,84 button "drawlight" size 120,30 Action Drawlight(ownd)
ACTIVATE WINDOW oWnd ;
ON PAINT DrawEllipse(ownd)
best regards
Uwe![Confused :?](./images/smilies/icon_confused.gif)
for my tests I'm using the basics from sample GDIPLUS3.prg
where I noticed the same problem.
It belongs to the button-action
Tested ( Green = OK )
@28,4 button "rectangle" size 120,30 Action Drawrectangle(ownd)
@28,24 button "roundrect" size 120,30 Action ( oWnd:Refresh(), ;
oWnd:bPainted := {|| Drawroundrect(ownd) } )
@28,44 button "drawImage" size 120,30 Action DrawImage(ownd)
@28,64 button "drawEllipse" size 120,30 Action DrawEllipse(ownd)
@28,84 button "drawlight" size 120,30 Action Drawlight(ownd)
ACTIVATE WINDOW oWnd ;
ON PAINT DrawEllipse(ownd)
best regards
Uwe
![Confused :?](./images/smilies/icon_confused.gif)
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: Save a bitmaphandle to file (jpg or png)
Mr. Rao, is functioning!
But in the ::save() this is not required!? In some case the filename become unreadable! z.B. C:\.... -> temp.jpg䤀䝔⁌㌲ᦑ
Code: Select all | Expand
oImage := GdiBmp():New()
oImage:hBmp := GDIP_FromHBitmap( hBitmap,,HasAlpha( hBitmap ) )
oImage:Save( "filenamewithExt" ) // for jpg, add nQuality as 2nd param
oImage:End()
But in the ::save() this is not required!? In some case the filename become unreadable! z.B. C:\.... -> temp.jpg䤀䝔⁌㌲ᦑ
Code: Select all | Expand
cCLSID = AnsiToWide( cCLSID )
cFile = AnsiToWide( cFile )
- nageswaragunupudi
- Posts: 10721
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 8 times
- Contact:
Re: Save a bitmaphandle to file (jpg or png)
Are you using any accented European characters in the filename?
Can you please test changing AnsiToWide( cFile ) as StrToWide( cFile ) ?
Also please let me know the exact filename you tried.
Can you please test changing AnsiToWide( cFile ) as StrToWide( cFile ) ?
Also please let me know the exact filename you tried.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
Re: Save a bitmaphandle to file (jpg or png)
No, not accented characters included?
Exact filename:
Trying msginfo(ansitowide("C:\WGUN\GUN1\IM_EX\TRAINING\xtemp.jpg")) shows only "C"!
Following files are produced (but not in all cases)
![Image](http://byte-one.com/xtemp.png)
Exact filename:
C:\WGUN\GUN1\IM_EX\TRAINING\xtemp.jpg
Trying msginfo(ansitowide("C:\WGUN\GUN1\IM_EX\TRAINING\xtemp.jpg")) shows only "C"!
Following files are produced (but not in all cases)
![Image](http://byte-one.com/xtemp.png)
Last edited by byte-one on Sun Feb 21, 2016 6:26 pm, edited 1 time in total.
Re: Save a bitmaphandle to file (jpg or png)
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
Re: Save a bitmaphandle to file (jpg or png)
Ok, We find the final solution
Regards
Regards
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
Re: Save a bitmaphandle to file (jpg or png)
This method should return .T. or .F. and also a DEFAULT for nQuality
Code: Select all | Expand
METHOD Save( cFile , nQuality ) CLASS GDIBmp