Solved

Copy System.Drawing.Graphics Objects

Posted on 2004-08-27
4
1,580 Views
Last Modified: 2011-09-20
Is there any way to copy (as in BitBlt), from one Graphics object to another without resorting to API calls?
0
Comment
Question by:eternal_21
  • 3
4 Comments
 
LVL 3

Accepted Solution

by:
GrumbleBot earned 500 total points
ID: 11918058
I think this should help. Not sure exactly what you need. This will copy the pixels from 0,0 - 50,50 of the bitmap in the picturebox and display it on the form at location 0,0. You could also copy it to anothe bitmap or picturebox.

      Graphics g = CreateGraphics();
      Bitmap myBitmap = (Bitmap) pictureBox1.Image;

      RectangleF cloneRect = new RectangleF(0, 0, 50, 50);
      PixelFormat format = myBitmap.PixelFormat;
      Bitmap cloneBitmap = myBitmap.Clone(cloneRect, format);
      g.DrawImage(cloneBitmap, 0, 0);

hope this helps.
Good luck
0
 
LVL 10

Author Comment

by:eternal_21
ID: 11920529
This is a good example of copying from a Bitmap to a Graphics object... but I need to go from one Graphics object to another.
0
 
LVL 3

Expert Comment

by:GrumbleBot
ID: 11921508
sorry about that. Hmm I'm pretty sure that the only way you will be able to do what you want is using BitBlt and get the hDC fo the graphics object. Here is an example in VB. Should be easy to modify to C#.

Sorry I couldn't help more. Hopefully there is an expert out there that has a easier way to do this.

Good luck
0
 
LVL 3

Expert Comment

by:GrumbleBot
ID: 11921513
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

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…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 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

17 Experts available now in Live!

Get 1:1 Help Now