DrawToBitmap方法问题 [英] DrawToBitmap method problem

查看:471
本文介绍了DrawToBitmap方法问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将此代码用于获取控件的图像.

I have used this code for Get image of my Control.

Dim bmp As New Bitmap(c.Width, c.Height)
scc.DrawToBitmap(bmp, New Rectangle(c.ClientRectangle.X, scc.ClientRectangle.Y, c.ClientRectangle.Width, c.ClientRectangle.Height))
bmp.Save("E:\Cur.bmp")



控件的 边框样式 是单个

但是它用
给图像 左&顶部边界一段时间
和somtime无国界


我想在控件的图像中显示所有边框
任何帮助...



Control''s Borderstyle is Single

But it give image with
Left & top borders some time
and somtime with no borders


I want all borders in image of my control
any help...

推荐答案

大家好,
我有解决方案.
我想与大家分享,希望对面临此类问题的人有所帮助.

奇怪的是,一种形式的代码可以很好地运行&以其他形式无法正常工作,仅显示左&因此,最后我必须执行如下所示的过程.

我已经两步走了,

第1步.
获取无边框控件的图像.
第2步.
在该图像的外部添加边框.
Hi all,
I got Solution.
I like to share with you all, hope it will be helpful to them who are facing this kind of problem.

It was really strange that in one form that code was simply runs fine & in other form it was not working properly, It was showing only left & top border of control so, Finally I have to do some process like below.

I have do it in tow steps,

step 1.
get Image of control without Border.
step 2.
Add border in that image externally.
c.BorderStyle = BorderStyle.None ' Set control's border style none
Dim bmp As New Bitmap(c.ClientSize.Width, c.ClientSize.Height) 
scc.DrawToBitmap(bmp, New Rectangle(0, 0, c.ClientSize.Width, c.ClientSize.Height)) 'Get image of Control (e.g here my control is 'c')
bmp = AppendBorder(bmp, 1) 'Set border Of Image. (you can set it in any color)
bmp.Save("E:\Cur.bmp", System.Drawing.Imaging.ImageFormat.Bmp)


Private Function AppendBorder(ByVal original As Image, ByVal borderWidth As Integer) As Image
     Dim borderColor As Color = Color.Gray ' select color for border of image
     Dim mypen As New Pen(borderColor, borderWidth * 2)
     Dim newSize As Size = New Size(original.Width + borderWidth * 2, original.Height + borderWidth * 2)

     Dim img As Bitmap = New Bitmap(newSize.Width, newSize.Height)
     Dim g As Graphics = Graphics.FromImage(img)

     g.DrawImage(original, New Point(borderWidth, borderWidth))
     g.DrawRectangle(mypen, 0, 0, newSize.Width, newSize.Height)
     g.Dispose()
     Return img
 End Function


我从网站 http://vbcity.com/forums/t/163882.aspx

祝您编码愉快!
:)


I got this AppendBorder function from site http://vbcity.com/forums/t/163882.aspx

Happy Coding!
:)


这篇关于DrawToBitmap方法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆