[英]What type should I use for saving images using C#?
I have this class called Hero that has the following attributes. 我有一个名为Hero的类,它具有以下属性。 String is for letters, int for numbers, etc. What can I use if I'm going to be saving an image there?
字符串用于字母,整数用于数字,等等。如果要在其中保存图像,该怎么办?
public class Hero
{
[Hero class's attributes (non-image related]
public byte[] Portrait { get; set; }
public byte[] Screenshot { get; set; }
}
Portrait and Screenshot are going to be .png or .jpg files. 纵向和屏幕截图将是.png或.jpg文件。 Should I use a byte[] array for them?
我应该为他们使用byte []数组吗? I'm a bit confused.
我有点困惑。
LOL, nevermind. 大声笑,没关系。 I figured out my error.
我发现了我的错误。 I had to use System.WINDOWS.Media.Imaging.
我不得不使用System.WINDOWS.Media.Imaging。 Go figure.
去搞清楚。
I'm going to be using them for just showing them on a WPF Form.
我将使用它们仅在WPF表单上显示它们。
BitmapImage is good for XAML based apps, or another derived class of BitmapSource may be more appropriate for your needs, otherwise just a plain old Bitmap . BitmapImage非常适合基于XAML的应用程序,或者BitmapSource的另一个派生类可能更适合您的需求,否则只是一个普通的Bitmap 。
There is an actual Bitmap class . 有一个实际的Bitmap类 。 I would strongly suggest against using a Byte array for it as that it could become corrupted and you would invalidate the image.
我强烈建议您不要使用Byte数组,因为它可能会损坏,并且会使图像无效。 If you kept it in a Bitmap object, you can directly pass the object to the PictureBox control and render it on the screen.
如果将其保存在Bitmap对象中,则可以将对象直接传递给PictureBox控件 ,然后在屏幕上呈现它。
Additonally, unlike the BMP format PNG [assuming] and JPG do not store the pixel format in the same fashion or representation. 另外,与BMP格式不同,PNG [假定]和JPG不会以相同的方式或表示形式存储像素格式。 JPG does model fitting [within blocks] (where it gets some of its savings and loses information) and stores the representation of the model instead of direct color values.
JPG进行模型拟合(在块内)(在其中进行部分节省并丢失信息),并存储模型的表示形式而不是直接的颜色值。
System.Drawing.Bitmap System.Drawing.Bitmap
http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx http://msdn.microsoft.com/zh-CN/library/system.drawing.bitmap.aspx
How are you going to be using them? 您将如何使用它们? The Image class might be more appropriate.
Image类可能更合适。 Bitmap might be another good one.
位图可能是另一个不错的选择。
EDIT: 编辑:
Then you'll want to use a BitmapImage . 然后,您将要使用BitmapImage 。 See also SO 94456 for some usage.
有关某些用法,另请参见SO 94456 。
It depends: 这取决于:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.