0

我正在尝试以下列方式设置面板的背景图像

 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 设置为背景图像..因为它可能会在服务器上部署时产生问题

4

1 回答 1

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

希望对你有帮助

于 2013-10-05T11:48:00.897 回答