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.
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.
This is an outdated answer from 2012, Adobe SVG view is no longer supported.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With