Can the picturebox be used to display vector-based images?

依然范特西╮ 提交于 2019-12-23 20:54:20

问题


Can the a PictureBox control be used to display vector-based images?

I have read a post from someone claiming that the PictureBox can be used to display vector-based images instead of bitmap images. So the box can be resized and the picture will retain its quality like a vector image should.

So I decided to try it out, although I am looking quality. Is it a problem with my vector images not being fully vector? If this is not possible, is there another way to do this without resorting to WPF?

I'm using VB.NET.


回答1:


Yes, that's possible. It has be a MetaFile, not a Bitmap. Best displayed by using the Paint() event so it can rescale on the fly as the picture box changes size. Sample code:

Public Class Form1
    Public Sub New()
        InitializeComponent()
        PictureBox1.Dock = DockStyle.Fill
        image = New System.Drawing.Imaging.Metafile(New System.IO.MemoryStream(My.Resources.schoolbus))
    End Sub

    Private Sub PictureBox1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
        e.Graphics.DrawImage(image, New Rectangle(Point.Empty, PictureBox1.ClientSize))
    End Sub

    Private Sub PictureBox1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Resize
        PictureBox1.Invalidate()
    End Sub

    Private image As System.Drawing.Imaging.Metafile

End Class

Where "schoolbus" was a sample .wmf file I added as a resource. The file format is the usual sticking point, there are not that many paint programs still supporting it. You can get one from here.




回答2:


PictureBox does not support vector-based images. If you do not want to use WPF, you might want to download an SVG view control. Here's one from Adobe: http://www.adobe.com/svg/viewer/install/

Once you installed it, the control DLL file should be located at, for example, C:\Program Files\Common Files\Adobe\SVG Viewer 3.0\NPSVG3.dll.

If you add the control on your form, you can load the file as stated below.

AxSVGCtl1.SRC = Filename

Using Adobe's SVG control from .NET shows how to use the SVG control in .NET although it is C# code.



来源:https://stackoverflow.com/questions/12585430/can-the-picturebox-be-used-to-display-vector-based-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!