FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Printing in GDI+
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM

Printing in GDI+

Posted: Thu Feb 09, 2017 03:05 PM

I found, that printing graphics made from GDI+ are ugly when using transparent modes. GDI+ has a own EMF-format. Maybe we should use it for this!?

Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Printing in GDI+

Posted: Thu Feb 09, 2017 03:27 PM
In FWH libraries, we are not using GDI+ for printing. We need to do more tests on this before implementation. For now we are using pure GDI only.

I found, that printing graphics made from GDI+ are ugly when using transparent modes. GDI+ has a own EMF-format. Maybe we should use it for this!?

Can you elaborate more please?
Regards



G. N. Rao.

Hyderabad, India
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM

Re: Printing in GDI+

Posted: Thu Feb 09, 2017 03:58 PM

Thanks. I will do some tests on next days before!

Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM

Re: Printing in GDI+

Posted: Thu Feb 09, 2017 06:07 PM

It is not a way to print transparent areas to most printers. We must write the graphic into bitmap (or EMF) an then draw the resulting bitmap (or play the EMF)!

Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM

Re: Printing in GDI+

Posted: Sun Feb 12, 2017 03:53 PM
It seems the method to print transparent areas or pages in GDI+ could as best with as first record in a EMF+ file and then play this file.
See also: https://msdn.microsoft.com/en-us/library/windows/desktop/ms536391(v=vs.85).aspx
I have tested with write to a empty bmp or png. Is functioning, but i must know the width and hight of the picture. In EMF+ the size is automatically adjusted and updated!
This all can (and should) be included in printer-class. If we use GDI+ then also the printer-output should be represent the features of GDI+.
Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Printing in GDI+

Posted: Sun Feb 12, 2017 06:07 PM

Can you please make me understand what is it we are going to achieve that we can not do with present print class using normal GDI? We are now able to print any image without using GDI+

Regards



G. N. Rao.

Hyderabad, India
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM

Re: Printing in GDI+

Posted: Mon Feb 13, 2017 09:05 AM
In the following link you see a image with transparent circles maked with GDI+. When paint this graphic i use a normal hDc and make a file. When this hDc is a printer i loose the transparence areas and full colors are painted on most printers.
http://byte-one.com/150.png
As first step you could use in printer/preview classes the EMF+ format from GDI+! This format saves also the tranparence!
Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Printing in GDI+

Posted: Mon Feb 13, 2017 10:43 AM
Nice.
I do not have the original png but I tried to view and print from your webpage.
Code (fw): Select all Collapse
//----------------------------------------------------------------------------//

function png150()

   local oWnd, oBar
   local cPng     := "http://byte-one.com/150.png"
   local aPalBmp

   DEFINE WINDOW oWnd
   DEFINE BUTTONBAR oBar OF oWnd SIZE 80,32
   DEFINE BUTTON OF oBar PROMPT "Print" CENTER ACTION PrintPng( cPng )

   aPalBmp  := oWnd:ReadPalBmpEx( cPng, , .t. )

   ACTIVATE WINDOW oWnd ON PAINT oWnd:SayPalBmp( aPalBmp )

   PalBmpFree( aPalBmp )

return nil

function PrintPng( cPng )

   local oPrn

   PRINT oPrn PREVIEW
   PAGE

   @ 4,2 PRINT TO oPrn IMAGE cPng SIZE 5,5 INCHES

   ENDPAGE
   ENDPRINT

return nil


I am able to see through the translucent circles.

Viewing in Window


Print Preview:


I see it well in my hard copy too.

Can you try this small program and kindly offer your comments?
Regards



G. N. Rao.

Hyderabad, India
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM

Re: Printing in GDI+

Posted: Mon Feb 13, 2017 11:06 AM
Yes, you are right! A complete picture to print is ok.
But to write to a printer-hDc (oPrint-class) the same transparent circles is not possible! Is always full color. Only some printers are able to print transparent output.
The png i make with CreateCompatibleBitMap( ) and write to a file.
Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Printing in GDI+

Posted: Mon Feb 13, 2017 12:30 PM
We need to address this:
But to write to a printer-hDc (oPrint-class) the same transparent circles is not possible!

Whether we directly write to print dc or otherwise, we need to have the final image on the printer.
Right?

Yes, I agree. Not all printer drivers support alpha colors.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1048
Joined: Mon Oct 24, 2005 09:54 AM

Re: Printing in GDI+

Posted: Mon Feb 13, 2017 01:00 PM

Thats the point!! This concerns not only transparency but also paths, transforms,....
Could this for the FWH-team a target?

Regards,
Günther
---------------------------------
office@byte-one.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: Printing in GDI+

Posted: Mon Feb 13, 2017 04:10 PM
What is now possible to do with FWH:
GDI+ Shapes (paths) in a simple way.
Code (fw): Select all Collapse
function TestShapes()

   local oWnd
   local aShapes   := {}
   local aShape

   // Triangle
   aShape   := { "Line", NARGB( 180, CLR_YELLOW ), 0, 1024, 1024, 0, 0, 1023, 0, 1023, 1023, .T. }
   AAdd( aShapes, aShape )
   aShape   := { "Line", CLR_HRED,                 3, 1024, 1024, 0, 0, 1023, 0, 1023, 1023, .T. }
   AAdd( aShapes, aShape )
   // Circle
   aShape   := { "Elli", NARGB( 128, CLR_HGREEN ), 0, 1024, 1024, 32, 32, 1023-32, 1023-32 }
   AAdd( aShapes, aShape )
   aShape   := { "Elli", CLR_GREEN,                3, 1024, 1024, 32, 32, 1023-32, 1023-32 }
   AAdd( aShapes, aShape )
   // Rectangle
   aShape   := { "Rect", NARGB( 128, CLR_BLACK ),  0, 1024, 1024, 484, 256, 640, 1023 }
   AAdd( aShapes, aShape )
   aShape   := { "Rect", CLR_WHITE,                6, 1024, 1024, 484, 256, 640, 1023 }
   AAdd( aShapes, aShape )

   DEFINE WINDOW oWnd TITLE "FWH GDI+ SHAPES"

   oWnd:nHeight      := 500
   oWnd:nWidth       := 400

   @ 400,40 BUTTON "Print" SIZE 100,30 PIXEL OF oWnd ;
      ACTION PrintShapes( aShapes )

   ACTIVATE WINDOW oWnd CENTERED ;
      ON PAINT oWnd:DrawShapes( aShapes, { 40, 40, 340, 340 } )

return nil

function PrintShapes( aShapes )

   local oPrn
   local hBmp

   hBmp     := FW_CreateBitmap( { 1024, 1024, aShapes } )

   PRINT oPrn PREVIEW
   PAGE

   // GDI+ draw on oPrn:hDCOut
   FW_DrawShapes( oPrn:hDCOut, aShapes, { 50,50,300,300 } )

   // Print as GDI Bitmap
   @ 4,1 PRINT TO oPrn IMAGE hBmp SIZE 4,4 INCHES

   ENDPAGE
   ENDPRINT

   DeleteObject( hBmp )

return nil


Window:


Print Preview:


Top image is drawn directly with GDI+ on the Printer's Preview DC (i.e, emf)
Bottom image is GDI Bitmap generated by GDI+ from the vector information of the Shapes

This prints on my printer. Not really sure how compatible is this with other printers.
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion