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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Scott LysleRank #49 · 31K reputationPosted Sep 8, 2007, 11:03 AM EDT
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))));shilpa bharkhada10 reputationPosted Sep 9, 2007, 8:09 PM EDT
Hi,
Thanks a lot....
Regards,
Shilpa