|
The drawing code remains completely unchanged.
[C#]
// clear the canvas to white
var pgRect = new Rectangle(0, 0, pg.Width, pg.Height);
var solidWhite = new SolidBrush(Color.White);
gr.FillRectangle(solidWhite, pgRect);
// load a new image and draw it centered on our canvas
using var stm = File.OpenRead(Server.MapPath("mypics/pic1.jpg"));
using var img = Image.FromStream(stm);
int w = img.Width;
int h = img.Height;
Rectangle rc = new Rectangle((pg.Width - w) / 2, (pg.Height - h) / 2, w, h);
gr.DrawImage(img, rc);
// frame the image with a black border
gr.DrawRectangle(new Pen(Color.Black, 4), rc);
// add some text at the top left of the canvas
Font fn = new Font("Comic Sans MS", 300);
var solidBlack = new SolidBrush(Color.Black);
gr.DrawString("My Picture", fn, solidBlack, (int)(pg.Width * 0.1), (int)(pg.Height * 0.1));
[Visual Basic]
' clear the canvas to white
Dim pgRect As New Rectangle(0, 0, pg.Width, pg.Height)
Dim solidWhite As New SolidBrush(Color.White)
gr.FillRectangle(solidWhite, pgRect)
' load a new image and draw it centered on our canvas
Dim stm As Stream = File.OpenRead(Server.MapPath("mypics/pic1.jpg"))
Dim img As Image = Image.FromStream(stm)
Dim w As Integer = img.Width
Dim h As Integer = img.Height
Dim rc As New Rectangle((pg.Width - w) / 2, (pg.Height - h) / 2, w, h)
gr.DrawImage(img, rc)
img.Dispose()
stm.Close()
' frame the image with a black border
gr.DrawRectangle(New Pen(Color.Black, 4), rc)
' add some text at the top left of the canvas
Dim fn As New Font("Comic Sans MS", 300)
Dim solidBlack As New SolidBrush(Color.Black)
gr.DrawString("My Picture", fn, solidBlack, DirectCast(pg.Width * 0.1, Integer), DirectCast(pg.Height * 0.1, Integer))
|
|
|