Hi,
How to do center allignment for diaplaying images with drawimage in c#.
Thanks in advance .
Shilpa
Hi,
How to do center allignment for diaplaying images with drawimage in c#.
Thanks in advance .
Shilpa
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
shilpa bharkhadaPosted Sep 10, 2007, 12:09 AM
Hi,
Thanks a lot....
Regards,
Shilpa
Scott LyslePosted Sep 8, 2007, 3:03 PM
Shilpa:
Find the center point where you intend to draw the image, then adjust the point by half the height and width of the image. Here is a simple example.
Bitmap bmp = new Bitmap("c:\\temp\\ICAM0001.JPG"); PointF pt = new PointF((float)this.ClientSize.Width / 2, (float)this.ClientSize.Height / 2); Graphics g = e.Graphics; g.DrawImage(bmp, new RectangleF((float)(pt.X - (bmp.Width ) / 2), (float)(pt.Y - (bmp.Height / 2)), (float)(bmp.Width * (.1)), (float)(bmp.Height * (.1))));