Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write to hDC with GDI+ in C#

Tags:

c#

gdi+

I have a int which represents the hDC handle of my display.

How can I draw a bitmap the the display in C#? Feel free to be as broad or as specific as you want. I'm not really clear how to proceed and all advice is appreciated.

This will eventually be an ArcEngine layer interface.

public class CustomLayer : ILayer
{

public void Draw(esriDrawPhase DrawPhase, IDisplay Display, ITrackCancel TrackCancel)
{
  int hdc = Display.hDC;
  //how to draw a bitmap?
}


}
like image 803
patrick Avatar asked Jan 18 '26 01:01

patrick


1 Answers

Graphics.FromHdc(hdc)

This gives you a nice .NET graphics object with good capability.

var graphics = Graphics.FromHdc(hdc);

// Create image.
Image newImage = Image.FromFile("Swans.bmp");

// Create Point for upper-left corner of image.
Point ulCorner = new Point(0, 0);

// Draw image to screen.
graphics.DrawImage(newImage, ulCorner);

More info here.

like image 150
agent-j Avatar answered Jan 19 '26 14:01

agent-j



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!