Save a bitmaphandle to file (jpg or png)

Save a bitmaphandle to file (jpg or png)

Postby byte-one » Sun Feb 21, 2016 11:08 am

Whats the best way (without FI)? Thanks
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

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

Postby ukoenig » Sun Feb 21, 2016 11:50 am

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

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

Postby byte-one » Sun Feb 21, 2016 12:01 pm

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

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

Postby nageswaragunupudi » Sun Feb 21, 2016 2:24 pm

Please try this and let us know if it works:
Code: Select all  Expand view
  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: 10595
Joined: Sun Nov 19, 2006 5:22 am
Location: India

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

Postby nageswaragunupudi » Sun Feb 21, 2016 3:01 pm

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 view
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
nageswaragunupudi
 
Posts: 10595
Joined: Sun Nov 19, 2006 5:22 am
Location: India

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

Postby ukoenig » Sun Feb 21, 2016 3:18 pm

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

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

Postby nageswaragunupudi » Sun Feb 21, 2016 3:21 pm

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
nageswaragunupudi
 
Posts: 10595
Joined: Sun Nov 19, 2006 5:22 am
Location: India

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

Postby ukoenig » Sun Feb 21, 2016 3:25 pm

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

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

Postby byte-one » Sun Feb 21, 2016 4:39 pm

Mr. Rao, is functioning!
Code: Select all  Expand view
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 view
cCLSID = AnsiToWide( cCLSID )
 cFile  = AnsiToWide( cFile )
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

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

Postby nageswaragunupudi » Sun Feb 21, 2016 5:19 pm

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
nageswaragunupudi
 
Posts: 10595
Joined: Sun Nov 19, 2006 5:22 am
Location: India

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

Postby byte-one » Sun Feb 21, 2016 6:20 pm

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

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

Postby cnavarro » Sun Feb 21, 2016 6:25 pm

At moment, try

Code: Select all  Expand view

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
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

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

Postby byte-one » Sun Feb 21, 2016 6:48 pm

Thanks, it seems to functioning!
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

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

Postby cnavarro » Sun Feb 21, 2016 6:50 pm

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
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

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

Postby byte-one » Mon Feb 22, 2016 11:18 am

This method should return .T. or .F. and also a DEFAULT for nQuality
Code: Select all  Expand view
METHOD Save( cFile , nQuality ) CLASS GDIBmp
Regards,
Günther
---------------------------------
office@byte-one.com
User avatar
byte-one
 
Posts: 1048
Joined: Mon Oct 24, 2005 9:54 am
Location: Austria

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 24 guests