使用图片做窗体怎么做啊
解决方案 »
- 用户发送一个消息,用ajax和Json传递数据的代码怎么写啊?
- webform如何调用winform?
- C#winfrom程序打包发布时安装mysql数据怎么做呢?
- C# 操作SQL如何达到最佳方案 老手请进,问题解决高分回报
- 初学c#,50分问一简单问题
- 我已知MSSQL服务器的IP地址及数据库名,可不知SA密码及其它密码,如何登录这个数据库,能不能通过编程登录这个MSSQL数据库??
- webbrowser 事件问题
- 打开一个 .aspx 的文件,为什么看不到,网页的设计页面?
- 如何让treeview的上下文菜单只在鼠标在子结点上右击时出现?高分求教。。。
- 大哥?哪边有可用的Visual Studio.Net 2003 http的下载
- Rtmp客户端?
- 求VB代码转换成C#
namespace IrregularFrom {
public class BitmapRegion {
public BitmapRegion() { }
public static void CreateControlRegion(Control control, Bitmap bitmap) { if (control == null || bitmap == null) return;
control.Width = bitmap.Width;
control.Height = bitmap.Height;
if (control is System.Windows.Forms.Form)
{
Form form = (Form)control;
form.Width = control.Width;
form.Height = control.Height;
form.FormBorderStyle = FormBorderStyle.None;
form.BackgroundImage = bitmap;
GraphicsPath graphicsPath = CalculateControlGraphicsPath(bitmap); form.Region = new Region(graphicsPath);
} else if(control is System.Windows.Forms.Button) {
Button button = (Button)control;
button.Text = "";
button.Cursor = Cursors.Hand;
button.BackgroundImage = bitmap;
GraphicsPath graphicsPath = CalculateControlGraphicsPath(bitmap); button.Region = new Region(graphicsPath);
}
}
private static GraphicsPath CalculateControlGraphicsPath(Bitmap bitmap) {
GraphicsPath graphicsPath = new GraphicsPath();
Color colorTransparent = bitmap.GetPixel(0, 0);
int colOpaquePixel = 0;
for (int row = 0; row < bitmap.Height; row++) { colOpaquePixel = 0;
for (int col = 0; col < bitmap.Width; col++) {
if (bitmap.GetPixel(col, row) != colorTransparent) {
colOpaquePixel = col;
int colNext = col;
for (colNext = colOpaquePixel; colNext < bitmap.Width; colNext++)
{
if (bitmap.GetPixel(colNext, row) == colorTransparent) break;
}
graphicsPath.AddRectangle(new Rectangle(colOpaquePixel, row, colNext - colOpaquePixel, 1));
col = colNext;
} }
}
return graphicsPath;
}
}
}
2.方法的使用
Bitmap bmp = Resource2.Image1 as Bitmap;//使用资源文件 BitmapRegion.CreateControlRegion(this, bmp);//窗体
Bitmap b = new Bitmap("../../wjx2.jpg");//使用本地文件 BitmapRegion.CreateControlRegion(this.button1, b);//按钮
Try
Using MyGp As New Drawing2D.GraphicsPath
MyGp.FillMode = Drawing2D.FillMode.Winding
MyGp.AddPolygon(GetPix(Me))
Me.Region = New Region(MyGp)
End Using
'====================================================
Catch ex As Exception
MessageBox.Show(ex.Message, "错误")
Me.DialogResult = Windows.Forms.DialogResult.Cancel
End Try
End Sub Private Function GetPix(ByVal Form As Control) As Point()
Dim MyPoint() As Point = Nothing
' Try
Using MyImage As New Drawing.Bitmap(My.Resources.Dark_GreenEarth_1)
Dim sum As Integer = 0
Dim MyControlImage As Bitmap = MyImage.GetThumbnailImage(Form.Width, Form.Height, Nothing, IntPtr.Zero)
Form.BackgroundImage = MyControlImage
'****************************************************
' 这里的代码最重要
' 注意:数组下标坐标点必须按照线条的顺序,否则则会出错
For x As Integer = 1 To MyControlImage.Width - 1
For y As Integer = 1 To MyControlImage.Height - 1
If MyControlImage.GetPixel(x, y).A > 125 Then ' 若显示有少许差错 请将 0 替换为 0~254 任意试试
ReDim Preserve MyPoint(sum)
MyPoint(sum).X = x
MyPoint(sum).Y = y
sum += 1
Exit For
End If
Next
Next For x As Integer = MyControlImage.Width - 1 To 1 Step -1
For y As Integer = MyControlImage.Height - 1 To 1 Step -1
If MyControlImage.GetPixel(x, y).A > 125 Then
ReDim Preserve MyPoint(sum) ' 若显示有少许差错 请将 0 替换为 1~255 任意试试
MyPoint(sum).X = x
MyPoint(sum).Y = y
sum += 1
Exit For
End If
Next
Next ' 由于时间仓促,不免有多少错误之处~
' 必须注意的是,像GIF,PNG格式背影为透明的图片,可能在某一段区域透明度为5,可能可能在某一段区域透明度为10......
' 请将代码按自已的需要优化
'**************************************************** End Using
Return MyPoint
' Catch ex As Exception
'MessageBox.Show(ex.Message)
' Return MyPoint
' End Try
End Function
#End Region