图片框可以用于显示基于矢量的图像吗? [英] Can the picturebox be used to display vector-based images?

查看:74
本文介绍了图片框可以用于显示基于矢量的图像吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我读过某人的帖子,声称PictureBox可用于显示基于矢量的图像图像而不是位图图像。因此,可以调整盒子的大小,并且图片将保留其质量,就像矢量图像一样。

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.

所以我决定尝试一下,尽管我一直在寻找质量。我的矢量图像不完全是矢量吗?如果不可能,是否有另一种方法可以不借助WPF?

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?

我正在使用VB.NET。

I'm using VB.NET.

推荐答案

是的,这是可能的。它是一个图元文件,而不是位图。最好通过使用Paint()事件来显示,以便在图片框更改大小时可以即时缩放。示例代码:

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

其中 schoolbus是我作为资源添加的示例.wmf文件。文件格式是通常的症结所在,仍然没有很多绘画程序支持它。您可以从这里获得一个

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.

这篇关于图片框可以用于显示基于矢量的图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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