471,066 Members | 1,227 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

Create a temp copy of a bitmap

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)
''''
Nov 21 '05 #1
2 2385
"John" <Jo**@discussions.microsoft.com> schrieb:
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 S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2

"John" <Jo**@discussions.microsoft.com> wrote in message
news:B9**********************************@microsof t.com...
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

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Programmer | last post: by
7 posts views Thread by lgbjr | last post: by
3 posts views Thread by radu | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.