Page 1 of 1

Printing in GDI+

Posted: Thu Feb 09, 2017 3:05 pm
by byte-one
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!?

Re: Printing in GDI+

Posted: Thu Feb 09, 2017 3:27 pm
by nageswaragunupudi
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?

Re: Printing in GDI+

Posted: Thu Feb 09, 2017 3:58 pm
by byte-one
Thanks. I will do some tests on next days before!

Re: Printing in GDI+

Posted: Thu Feb 09, 2017 6:07 pm
by byte-one
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)!

Re: Printing in GDI+

Posted: Sun Feb 12, 2017 3:53 pm
by byte-one
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+.

Re: Printing in GDI+

Posted: Sun Feb 12, 2017 6:07 pm
by nageswaragunupudi
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+

Re: Printing in GDI+

Posted: Mon Feb 13, 2017 9:05 am
by byte-one
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!

Re: Printing in GDI+

Posted: Mon Feb 13, 2017 10:43 am
by nageswaragunupudi
Nice.
I do not have the original png but I tried to view and print from your webpage.

Code: Select all | Expand

//----------------------------------------------------------------------------//

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
Image

Print Preview:
Image

I see it well in my hard copy too.

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

Re: Printing in GDI+

Posted: Mon Feb 13, 2017 11:06 am
by byte-one
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.

Re: Printing in GDI+

Posted: Mon Feb 13, 2017 12:30 pm
by nageswaragunupudi
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.

Re: Printing in GDI+

Posted: Mon Feb 13, 2017 1:00 pm
by byte-one
Thats the point!! This concerns not only transparency but also paths, transforms,....
Could this for the FWH-team a target?

Re: Printing in GDI+

Posted: Mon Feb 13, 2017 4:10 pm
by nageswaragunupudi
What is now possible to do with FWH:
GDI+ Shapes (paths) in a simple way.

Code: Select all | Expand

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:
Image

Print Preview:
Image

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.