如何将图像存储在矢量中?

时间:2014-04-13 09:43:21

标签: c# arrays

您可以将图像存储在矢量中吗?如果是的话,你是怎么做到的?我知道在C#中你是用指针做的。这里指针的对应部分是什么?

编辑:

byte[] pngBytes = File.ReadAllBytes(@"C:\myphoto.png");
List<byte[]> images = new List<byte[]>();
images.Add(pngBytes);

EDIT2:

public class WineModel
{
    public WineModel (byte[] bytes, string description)
       {
           this.Bytes = bytes;
           this.Description = description;
        }

public byte[] Bytes {get;set;}
public string Description {get;set;}
}

EDIT3:

 var button = new KinectTileButton
              {
                  Label = System.IO.Path.GetFileNameWithoutExtension(file),

                  Background = new ImageBrush(bi),
                   Tag = wineModel
              };

代码XAML:

  <WrapPanel VerticalAlignment="Center" x:Name="wrapPanel" Orientation="Vertical" k:KinectTileButton.Click="KinectTileButtonClick">
            <!-- items for design layout.  They will be replaced at runtime. -->
            <k:KinectTileButton Label="1" Click="KinectTileButton_Click" />
            <k:KinectTileButton Label="2"/>
            <k:KinectTileButton Label="3"/>
            <k:KinectTileButton Label="4"/>
            <k:KinectTileButton Label="5" Click="KinectTileButton_Click_1" />
            <k:KinectTileButton Label="6"/>
            <k:KinectTileButton Label="7"/>
            <k:KinectTileButton Label="8"/>
            <k:KinectTileButton Label="9"/>
            <k:KinectTileButton Label="10"/>

        </WrapPanel>

1 个答案:

答案 0 :(得分:0)

您无法对PNG进行矢量化。仅仅因为图像被保存为具有特定颜色的像素。

您可以将图像保存在数组中,但随后将是字节。

要将图像保存在列表中,请定义此类:

public class ImageInfo
{
    public ImageInfo(Image image, string description)
    {
        this.Image = image;
        this.Description = description;
    }

    public Image Image {get;set;}
    public string Description {get;set;}
}

在你的阅读方法中:

List<ImageInfo> images = new List<ImageInfo>();

Image image = Image.FromFile(@"C:\myphoto.png");

images.Add(new ImageInfo(image, "this is a description"));

...

pictureBox1.Image = images[0].Image;