Vb.net使用按钮将面板转换为.png [英] Vb.net convert panel into .png using button

查看:114
本文介绍了Vb.net使用按钮将面板转换为.png的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Panel转换为.png格式?我尝试将其转换为.pdf,但pdf阅读器中的文件大小很短(我正在做景观大小)



我尝试了什么:



how can i convert the Panel into a .png format? i tried converting it into .pdf but the size of file is short in pdf reader (im doing a landscape size)

What I have tried:

'convert panel to .pdf

 Dim MyPdfFilePath As String = "C:\Documents\test\test.pdf"
    Dim PdfDoc As New iTextSharp.text.Document()
    Dim PdfImg As iTextSharp.text.Jpeg

    Using bm As New Bitmap(Panel1.Width, Panel1.Height)
        Panel1.DrawToBitmap(bm, New Rectangle(0, 0, bm.Width, bm.Height))
        Using ms As New MemoryStream
            bm.Save(ms, Imaging.ImageFormat.Jpeg)
            PdfImg = New iTextSharp.text.Jpeg(ms.GetBuffer)
        End Using
    End Using

    Using fs As New FileStream(MyPdfFilePath, FileMode.Create, FileAccess.Write, FileShare.None)

        Using pdfWrite As iTextSharp.text.pdf.PdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(PdfDoc, fs)

            PdfDoc.Open()
            PdfDoc.Add(PdfImg)
            PdfDoc.Close()
        End Using
    End Using

    PdfDoc.Dispose()





编辑我现在可以使用下面的代码段将面板转换为.png。但我现在的问题是如何才能提高png的分辨率?





EDIT i can now convert the panel into .png using the snippet below. But my problem now is how can i increase the resolution of the png ?

'panel convert to .png format
Try
        Using bmp = New Bitmap(Panel1.Width, Panel1.Height)
            Panel1.DrawToBitmap(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height))
            bmp.Save("C:\Documents\test\image.png")
        End Using
        MessageBox.Show("Image saved successfully.")
    Catch
        MessageBox.Show("Error.....")
    End Try
End Sub

推荐答案

例如:

For example like this :
Using bmp = New Bitmap(Panel1.Width, Panel1.Height)
      Panel1.DrawToBitmap(bmp, New Rectangle(0, 0, bmp.Width, bmp.Height))

      Dim bmp2 As New Bitmap(bmp.Width * 3, bmp.Height * 3)
      Dim gr As Graphics = Graphics.FromImage(bmp2)
      gr.DrawImage(bmp, New Rectangle(0, 0, bmp2.Width, bmp2.Height))

      bmp2.Save("C:\Documents\test\image.png")
End Using





我使用固定缩放。当然你可以使用一个变量。

但是你应该意识到,这样图像才会成倍增加 - 而不是更多的信息.​​.....



I worked with a fixed scaling. Of course you can use a variable for this.
But you should realize that in this way the Image only becomes multiplied - not more Information ...


这篇关于Vb.net使用按钮将面板转换为.png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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