Click here to Skip to main content
13,095,218 members (71,154 online)
Rate this:
Please Sign up or sign in to vote.
See more:

Please let me know , If you know any solution to make an image file or binary file from the image that has been drawn in the

I want to draw text using instead of using bitmap because drawing on has high quality and then I want to have a copy of the data on that.

How I can copy later the content of the saved file on again for printing?

Posted 27-Feb-13 5:58am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Here is what you can do:

You render your graphics by overriding System.Windows.Forms.OnPaint or handling the event System.Windows.Forms.Paint. It's simpler to show the first case:

public partial class MyControl { // base class is some control of Form, suppose the base class is shown in other partial part
    protected virtual void OnPaint(PaintEventArgs e) {
        // do something
} //class MyControl

What is that "do something"? This is your rendering I assume you already have. All you need to do it to abstract out this rendering from particular instance of System.Drawing.Graphics. Again:

    protected virtual void OnPaint(PaintEventArgs e) {
    void Render(System.Drawing.Graphics graphics) {
        // use graphics the way you did before

Are you getting the idea? Now, the method void Render(System.Drawing.Graphics) is something you can reuse for instances of System.Drawing.Graphics of different nature. It's already used for on-screen rendering, but what else could you do with it? Right, you can call it with printing or bitmap graphics.

Create a bitmap first, of appropriate size; please see the first link below. To get the instance of System.Drawing.Graphics to be used for drawing on some bitmap, you use this static factory method:[^].

Now you can draw on a bitmap and save this bitmap:[^],[^],[^],[^].

Now, a bonus: you can use the same rendering method with an instance of System.Drawing.Graphics used for printing:[^].

Good luck,
afshinsh 27-Feb-13 14:36pm
Hi Sergey
Thanks a lot for your answer, would you please send a simple project that writes a simple text on e.graphic and saves it on a file and fetch it from the file.
the reason that i can't use print document is this that when there is too many pages to print it will slow down.
I appreciate that.
Sergey Alexandrovich Kryukov 27-Feb-13 14:51pm
For goodness sake, no! It would take too much time.
I have an unfinished article with complete code which cover this and a lot more. This "a lot" make my doubtful. If you kind of reluctant to do you job by yourself, I'm not sure you will agree to scan through all my code, as it's big. :-)

My answer is already much more detailed than a typical forum answer. You have absolutely everything you need. Please, don't be so lazy. The most effective way it so use your own project. Of course, you are welcome to ask more questions is you stuck.

And please accept my answer formally (green button); it has all you need and even more... thanks.

Sergey Alexandrovich Kryukov 27-Feb-13 14:59pm
As to the PrintDocument, being slow is not an argument. Do you know how to print faster? I don't think so. You should use it, but perhaps allow to print separate parts separately. Printing should not really delay execution much. When it all is sent to printer, it does not delay anything...
afshinsh 27-Feb-13 16:00pm
Thanks a lot Sergey,
The reason I asked is my lack of knowledge in c# understanding your comment, anyway I will do my best to find it out and thanks for your time.
Sergey Alexandrovich Kryukov 27-Feb-13 16:18pm
Nevertheless, you are welcome to ask further question if you stuck.
Good luck, call again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 27 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100