GDI+Desktop graphics and printing library

agraham

Expert
Licensed User
Longtime User
This major new desktop and .NET 2.0 only library is upwardly compatible with ImageLibEx and adds a load of additional graphics functionality that only exists on the desktop GDI+ graphics system. It also fully supports printing, including page setup and print preview, so that anything you can draw on an image can also be printed.

To a certain extent you are on your own using this library, I can document the functionality but I can't teach you how to use it. If you can use ImageLib or ImageLibEx you can easily get the same things printed and the additional graphics capabilities are pretty straightforward to use.. However to use some of the more advanced MeasureString and DrawString methods to format text will need some trial and error (probably lots of error!) and/or some research on the Web. To ease the problem of text formatting I have copied over the Rich Text Format printing support from my RichTextDesktop library, and improved it so that Rich Text can now be rendered on an image as well as being printed.

The output of the demo app included is a bit bit scrappy. As I have stated before I am not a "graphics" person and unlike some people I know who get a buzz out of writing graphics code I get bored doing it - my forte is the abstract stuff. Please therefore look past what the output looks like and examine what the library can do and how it does it.

It is probably as well to regard this first release as somewhat of a beta version as, due to the extent of the functionality of the thing, I have not been able (or willing!) to try many things in combination so I'm sure there will be some bugs and lots of errors in the help (I got really bored writing the help :().

EDIT :- Version1.1 posted with minor tweak to BitmapEx.Zoom memory management and BitmapEx.Zoom documented in the help.

EDIT : - Version 1.2 with some additional functions to match ImageLibEx improvements. See post #3 for details.

EDIT : - Version 1.3 allows some page settings to be changed for an individual page during the printing process. See post #8 for details.

EDIT : - Version 1.4 posted to match the changes in ImageLibEx 2.0. See post #10 for details.
 

Attachments

  • GDI+Desktop1.4.zip
    93.7 KB · Views: 192
Last edited:

agraham

Expert
Licensed User
Longtime User
Version 1.1 now posted with a very minor tweak to BitmapEx.Zoom memory management to dispose of an internal Bitmap object rather than rely upon the .NET garbage collector.

BitmapEx.Zoom is now documented in the help. It existed previously but I missed including it in the help.
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Version 1.2 has the three improvements requested by Klaus for ImageLibEx.

FloodFill.Flood overwrites everything until a specified boundary color is found.

DrawerEX.DrawCircle draws a circle.

DrawerEX.FillCircle draws a filled circle.

Also added are DrawerEx.ARGB() and DrawerEx.GetARGB. These are similar to Basic4ppc RGB() and GetRGB() but include the alpha component of a desktop color.
 

corwin42

Expert
Licensed User
Longtime User
Hello Andrew,

I use your GDI+ Library to print some pages. I need to set the left and right margin individual for each page (left pages have another margin than right pages).

In the help file under the printer object section there is an Event QueryPageSettings explained.

QueryPageSettings : Occurs immediately before each PrintPage event. It is possible to print each page of a document using different page settings. You set page settings by modifying individual properties of the QueryPageSettingsEventArgs.PageSettings property or by setting the property to a PageSettings. Changes made to the PageSettings affect only the current page, not the document's default page settings. The print job can also be canceled by setting the Cancel property to true for the QueryPageSettingsEventArgs.

I don't understand this completely. As I understand this, in this event call I should be able to set the margin for my page. I just tried to set printer.LeftMargin to another value but this does not work.

Can you explain it in more detail or do you have an example for this?

I think I have to use the door.library to obtain the QueryPageSettingsEventArgs.PageSettings property?

Thanks,
Markus
 

agraham

Expert
Licensed User
Longtime User
Try this and post the results. There are 6 new properties

Cancel - stops printing when set in the event Sub for any of the events.

The following are page settings that may be read/written within the PrintPageEvent or QueryPageEvent. It is not clear from the .NET documentation whether modifying these settings has different effects in the two events or not.

PsLandscape
PsLeftMargin
PsRightMargin
PsTopMargin
PsBotttomMargin
 

Attachments

  • GDI+Desktop1.21.zip
    15.1 KB · Views: 44

corwin42

Expert
Licensed User
Longtime User
Works perfectly.

If you change these properties in the QueryPageSettings event then you get the correct margin sizes in the PrintPage event with printer.Marginbounds.

Changing the properties in PrintPage doesn't seem to work.

Thanks very much.
 
Last edited:

corwin42

Expert
Licensed User
Longtime User
Hi Andrew,

if you make a new release (with .cs file) of this version, I will share my little Application. I think its a good example of what can be done with Basic4PPC in really short time. :sign0060:

Thanks very much again for your extremely fast support.
 

corwin42

Expert
Licensed User
Longtime User
Weekly Calendar example

Ok, here is a more complex example of what can be done with this library. This program was hacked together in just one day. I think this shows the power of Basic4PPC and its additional libraries.

Needs Version 1.3 or above of GDI+Desktop Library

The program just creates a weekly calendar (dates are configurable) that you can print out. Have fun with it.
 

Attachments

  • WeeklyCalendar.sbp
    13.7 KB · Views: 68

berndgoedecke

Active Member
Licensed User
Longtime User
Error cs1525 during compilation

Hello AGraham,
I use GDI Desktop to save a Bitmap to a File like this:
BMapExCop.SaveImage(AppPath & "\Temp\Blob.jpg")
It works in the Editor even if the GDI Desktop Help references another syntax like this:
BMapExCop.SaveImage(PathName As String, Channel As String, Format As String)
During compilation I get the cs1525 error.
What is wrong?

Best regards

berndgoedecke
 

Attachments

  • CS1525.jpg
    CS1525.jpg
    12.4 KB · Views: 10

agraham

Expert
Licensed User
Longtime User
What is wrong?
There's nothing wrong. The method call should have a format parameter. The IDE isn't strict enough in its' checking, it really should give you an error. You don't get an error from the library because it defaults to JPG if it doesn't understand the format string, or lack of, given to it.
 

berndgoedecke

Active Member
Licensed User
Longtime User
BitBlit

Hello AGraham,
i've tried some kind of Syntax in the BitBlit-command:

BMapExCopM.Value = BMapExCopM.BitBlt(BMapExCop.Value, StrRec.Value, 0, 0, D=D<S )

or

BMapExCopM.Value = BMapExCop.BitBlt(BMapExCop.Value, StrRec.Value, 0, 0, D=D<S )

or

SRCCOPY = 13369376 '(&HCC0020)
BMapExCopM.Value = BMapExCopM.BitBlt(BMapExCop.Value, StrRec.Value, 0, 0, SRCCOPY)

or

SRCCOPY = 13369376 '(&HCC0020)
BMapExCopM.Value = BMapExCop.BitBlt(BMapExCop.Value, StrRec.Value, 0, 0, SRCCOPY)

but always appears the error "Raster op is not valid".
How this function operates?

Best regards

berndgoedecke
 

agraham

Expert
Licensed User
Longtime User
From the help

BitBlit(src As Image, srcrect As Rectangle, destleft As Int32, desttop As Int32, rasterop As String )

Also there is no return value from BitBlit

"The existing internal bitmap is modified."

try

BMapExCopM.BitBlt(BMapExCop.Value, StrRec.Value, 0, 0, "D=D<S")
 
Top