Solved

Copy System.Drawing.Graphics Objects

Posted on 2004-08-27
4
1,582 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

914 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

16 Experts available now in Live!

Get 1:1 Help Now