我试图按照以下方式设置面板的背景图像
Dim bmp As New Bitmap(1500, 2500)
Dim g As Graphics = System.Drawing.Graphics.FromImage(bmp)
DrawTimeScale(g)
g.Flush()
Dim img_converter As New ImageConverter()
Dim bytes As Byte() = DirectCast(img_converter.ConvertTo(bmp, GetType(Byte())), Byte())
File.WriteAllBytes(Server.MapPath("~/Images/OT.jpeg"), bytes)
pnl001.BackColor = Color.White
pnl001.BackImageUrl = "~/Images/OT.jpeg"
pnl001.Attributes.Add("style", "background-repeat:no-repeat")
但是,由于代码显示我需要每次在服务器中显示图像。我可以直接将bmp设置为背景图像..因为它可能会在服务器上部署时产生问题
答案 0 :(得分:0)
试试这个
Imports System.Runtime.InteropServices
Public Class Form1
Dim bmp As Bitmap
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
e.Graphics.DrawImage(bmp, New Rectangle(20, 20, Panel1.Width - 20, Panel1.Height - 20), New Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Using s As System.IO.Stream = New System.IO.FileStream("E:\temp\bmp\right.bmp", IO.FileMode.Open, IO.FileAccess.Read)
bmp = Bitmap.FromStream(s)
End Using
Panel1.BorderStyle = BorderStyle.Fixed3D
End Sub
End Class
希望它可以帮助你