可以使用图片框来显示基于矢量的图像吗?

时间:2012-09-25 14:44:35

标签: c# vb.net visual-studio-2010 components

可以使用a PictureBox控件来显示基于矢量的图像吗?

我已经阅读了某人的帖子,声称PictureBox可用于显示基于矢量的图像而不是位图图像。因此可以调整框的大小,图片将像矢量图像一样保持其质量。

所以我决定尝试一下,虽然我看起来质量很好。这是我的矢量图像不是完全矢量的问题吗?如果这是不可能的,有没有其他方法可以做到这一点,而不诉诸WPF?

我正在使用VB.NET。

2 个答案:

答案 0 :(得分:6)

是的,这是可能的。它是MetaFile,而不是Bitmap。最好使用Paint()事件显示,以便它可以随着图片框改变大小而动态重新缩放。示例代码:

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

“schoolbus”是我作为资源添加的示例.wmf文件。文件格式是通常的关键点,没有那么多的绘图程序仍然支持它。您可以获得一个from here

答案 1 :(得分:3)

PictureBox不支持基于矢量的图像。如果您不想使用WPF,则可能需要下载SVG视图控件。这是来自Adobehttp://www.adobe.com/svg/viewer/install/

安装后,控制DLL文件应位于,例如, C:\Program Files\Common Files\Adobe\SVG Viewer 3.0\NPSVG3.dll

如果您在表单上添加控件,则可以按如下所述加载文件。

AxSVGCtl1.SRC = Filename

Using Adobe's SVG control from .NET 显示了如何在.NET中使用SVG控件,尽管它是C#代码。