Create a temp copy of a bitmap

G

Guest

The following 4 lines add a border to a bitmap and save it into clipboard,
however it also add a border to the bitmap on the screen.

I want to create a temp copy of the bitmap and add a border to it without
affecting the bitmap on the screen. Any suggestions? Thanks

'''''
Dim g As Graphics = Graphics.FromImage(MyPpic.Image)
Dim pen As New Pen(Color.Gray)
g.DrawRectangle(pen, 0, 0, MyPpic.Image.Width - 1,
MyPpic.Image.Height - 1) ' draw border
Clipboard.SetDataObject(MyPpic.Image)
''''
 
H

Herfried K. Wagner [MVP]

John said:
The following 4 lines add a border to a bitmap and save it into clipboard,
however it also add a border to the bitmap on the screen.

I want to create a temp copy of the bitmap and add a border to it without
affecting the bitmap on the screen. Any suggestions? Thanks

'''''
Dim g As Graphics = Graphics.FromImage(MyPpic.Image)
Dim pen As New Pen(Color.Gray)
g.DrawRectangle(pen, 0, 0, MyPpic.Image.Width - 1,
MyPpic.Image.Height - 1) ' draw border
Clipboard.SetDataObject(MyPpic.Image)
''''

You will have to create a new 'Bitmap' object, get a 'Graphics' object and
draw the original image and the border onto the temporary bitmap.

\\\
Dim b As New Bitmap(100, 100, ...)
Dim g As Graphics = Graphics.FromImage(b)
g.DrawImage(x, ...)
g.DrawRectangle(...)
g.Dispose()
Clipboard.SetDataObject(b)
///
 
M

Mythran

John said:
The following 4 lines add a border to a bitmap and save it into clipboard,
however it also add a border to the bitmap on the screen.

I want to create a temp copy of the bitmap and add a border to it without
affecting the bitmap on the screen. Any suggestions? Thanks

'''''
Dim g As Graphics = Graphics.FromImage(MyPpic.Image)
Dim pen As New Pen(Color.Gray)
g.DrawRectangle(pen, 0, 0, MyPpic.Image.Width - 1,
MyPpic.Image.Height - 1) ' draw border
Clipboard.SetDataObject(MyPpic.Image)
''''

Clone the graphics object first, as follows:

Dim img As Image = MypPic.Image.Clone()
Dim g As Graphics = Graphics.FromImage(img)
Dim pen As Pen = New Pen(Color.Blue)
g.DrawRectangle(pen, 0, 0, img.Width - 1, img.Height - 1)
Clipboard.SetDataObject(img)


HTH,
Mythran
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top