Save a bitmaphandle to file (jpg or png)

User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Save a bitmaphandle to file (jpg or png)

Post by byte-one »

Whats the best way (without FI)? Thanks
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
ukoenig
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Save a bitmaphandle to file (jpg or png)

Post by ukoenig »

Günther,

can You explain in detail ( maybe a sample ), what exactly You want to do ?

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.
User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Re: Save a bitmaphandle to file (jpg or png)

Post by byte-one »

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
 
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
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)

Post by nageswaragunupudi »

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
User avatar
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)

Post by nageswaragunupudi »

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.

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

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
User avatar
ukoenig
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Save a bitmaphandle to file (jpg or png)

Post by ukoenig »

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 :?:
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.
User avatar
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)

Post by nageswaragunupudi »

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
User avatar
ukoenig
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Save a bitmaphandle to file (jpg or png)

Post by ukoenig »

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 :?
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.
User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Re: Save a bitmaphandle to file (jpg or png)

Post by byte-one »

Mr. Rao, is functioning!

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 )
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
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)

Post by nageswaragunupudi »

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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Re: Save a bitmaphandle to file (jpg or png)

Post by byte-one »

No, not accented characters included?
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
Last edited by byte-one on Sun Feb 21, 2016 6:26 pm, edited 1 time in total.
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: Save a bitmaphandle to file (jpg or png)

Post by cnavarro »

At moment, try

Code: Select all | Expand


cFile  := AnsiToWide( cFile + Chr(0) )

 
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
User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Re: Save a bitmaphandle to file (jpg or png)

Post by byte-one »

Thanks, it seems to functioning!
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: Save a bitmaphandle to file (jpg or png)

Post by cnavarro »

Ok, We find the final solution

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
User avatar
byte-one
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria
Contact:

Re: Save a bitmaphandle to file (jpg or png)

Post by byte-one »

This method should return .T. or .F. and also a DEFAULT for nQuality

Code: Select all | Expand

METHOD Save( cFile , nQuality ) CLASS GDIBmp
Regards,
Günther
---------------------------------
office@byte-one.com
Post Reply