By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,257 Members | 928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,257 IT Pros & Developers. It's quick & easy.

how to get co-ordinates to write on image

P: n/a
I am writing Hello on the image i am able to write it sucessfully now I want
to

write it at bottom right corner

How can I calculate the co-ordinates(suppose my image is 600*450)

string str="Hello";

Bitmap tempImage=new
System.Drawing.Bitmap(Server.MapPath("/Photos/21/Normal/1.jpg"));

Graphics graphicImage=System.Drawing.Graphics.FromImage(tem pImage);

graphicImage.DrawString(str,new Font("Arial", 10,FontStyle.Regular),new
SolidBrush(Color.Black),new Point(0,0));

Response.ContentType="image/jpeg";

tempImage.Save("D:/test.jpg",ImageFormat.Jpeg);

graphicImage.Dispose();

tempImage.Dispose();
Jun 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Vikas,

Thanks for your post!

The Point you passed to DrawString method specifies which point to draw the
string. To draw in the bottom right corner of the image, you may pass the
bottom right point coordinate as the point parameter, and then pass an
extra StringFormat parameter to DrawString method. You should set
StringFormat.Alignment and LineAlignment properties to StringAlignment.Far
so that the string drawing start with a different alignment. Sample code
snippet is listed below:

Bitmap tempImage=new
System.Drawing.Bitmap(600, 450);
Graphics graphicImage=System.Drawing.Graphics.FromImage(tem pImage);
string str="Hello";

StringFormat sf=new StringFormat();
sf.Alignment=StringAlignment.Far;
sf.LineAlignment=StringAlignment.Far;

graphicImage.DrawString(str,new Font("Arial", 10,FontStyle.Regular),new
SolidBrush(Color.Black),new Point(600,450), sf);

tempImage.Save(@"C:\test.jpg");
graphicImage.Dispose();
tempImage.Dispose();

Note:
1. in the code, I create an empty memory bitmap for drawing, and then save
it to disk. You can open this bitmap in disk to see the final effect.
2. the default StringFormat for DrawString method is StringAlignment.Near
which uses the (600, 450) point as the top-left drawing point, so draws the
string out of your image rectangle. By changing the alignment to
StringAlignment.Far, it will use (600, 450) point as the bottom-right
drawing point

You may modify the code snippet a little to use it in Asp.net HttpResponse
class.

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 20 '06 #2

P: n/a
thanks
""Jeffrey Tan[MSFT]"" <je***@online.microsoft.com> wrote in message
news:P5**************@TK2MSFTNGXA01.phx.gbl...
Hi Vikas,

Thanks for your post!

The Point you passed to DrawString method specifies which point to draw
the
string. To draw in the bottom right corner of the image, you may pass the
bottom right point coordinate as the point parameter, and then pass an
extra StringFormat parameter to DrawString method. You should set
StringFormat.Alignment and LineAlignment properties to StringAlignment.Far
so that the string drawing start with a different alignment. Sample code
snippet is listed below:

Bitmap tempImage=new
System.Drawing.Bitmap(600, 450);
Graphics graphicImage=System.Drawing.Graphics.FromImage(tem pImage);
string str="Hello";

StringFormat sf=new StringFormat();
sf.Alignment=StringAlignment.Far;
sf.LineAlignment=StringAlignment.Far;

graphicImage.DrawString(str,new Font("Arial", 10,FontStyle.Regular),new
SolidBrush(Color.Black),new Point(600,450), sf);

tempImage.Save(@"C:\test.jpg");
graphicImage.Dispose();
tempImage.Dispose();

Note:
1. in the code, I create an empty memory bitmap for drawing, and then save
it to disk. You can open this bitmap in disk to see the final effect.
2. the default StringFormat for DrawString method is StringAlignment.Near
which uses the (600, 450) point as the top-left drawing point, so draws
the
string out of your image rectangle. By changing the alignment to
StringAlignment.Far, it will use (600, 450) point as the bottom-right
drawing point

You may modify the code snippet a little to use it in Asp.net HttpResponse
class.

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Jun 20 '06 #3

P: n/a
You are welcome

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 21 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.