Convert a Graphics object into Bitmap

Posted on 2005-04-06
Last Modified: 2008-02-01

    I need to create a image using the Graphics Object. That means, in my system i'm drawing few lines and i want load it into a picture box. What i thaught was to convert the Graphics object into a bitmap and include the bitmap in the picture box. but i'm not sure how to do this. Can please tell me how to do this?

Question by:lilanw
    LVL 8

    Accepted Solution

    Try something like this:
    int width = 100,height=100;
    Bitmap YourBMP = new Bitmap(width,height);
    Graphics g = Graphics.FromImage(YourBMP);
    ///Draw anything you want on g
    pictureBox1.Image = YourBMP;
    LVL 10

    Expert Comment

    The Graphics object is a drawing adapter to a device or image. The Graphics object does not contain an image. It's only a adapter to the screen buffer or a bitmap.
    For your case it would be the easiest to paint on the bitmap like RomanPetrenko showed you above and then Draw the bitmap on your form or display it in a picture box. (Then the picture box does the drawing for you.)
    LVL 8

    Expert Comment

    I think the answer I gave is complete. Can it be graded?

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now