图像没有压缩到位图?

时间:2013-04-06 03:18:41

标签: c# image bitmap png

我有一个使用png的程序,当我将它们放入资源时,它们被降级为仅支持24位颜色的位图。有没有办法可以保持图像质量不被搞砸?

   private void Form1_Load_1(object sender, EventArgs e)
    {
        Image NSMBWImg = (Image)Properties.Resources.NSMBWImg;
        Image OkamiImg = (Image)Properties.Resources.OkamiImg;
        Game NSMBW = new Game("New Super Mario Bros. Wii", "Nintendo", "Nintendo", "November 15,2009", "Wii", "2D Platformer", "4", "Mario leaps into an all new adventure! Scramble through courses with up to four players at the same time! Run, stomp, and fly through eight worlds packed with enemies and surprises.", NSMBWImg);
        Game Ookami = new Game("Ōkami", "Clover Studio", "Capcom", "PS2: September 19, 2006 Wii: April 15, 2008", "PS2/Wii", "Action-adventure", "1", "Play as the wolf incarnation of the Japanese sun goddess Amaterasu and channel your divine powers through the mighty celestial paintbrush to restore beauty and order to a bleak world overrun by evil.", OkamiImg);
        Games.Add(NSMBW);
        Games.Add(Ookami);
    }

我想确保图像质量不会改变,我可能只是在网站上托管图像吗?或者可能将其包含在文件夹中而不将其放入资源中?

1 个答案:

答案 0 :(得分:0)

将png文件添加到项目中(从解决方案资源管理器中右键单击项目 - >添加现有项目),然后在文件属性中添加后,将Build Action设置为:Embedded Resource。

enter image description here

然后加载您的图片

    using(Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("<root namespace for the assembly>.<folder name>.<image file name>"))
{
    Image = Image.FromStream(stream);
}

另一个例子

using (
            Stream stream =
                Assembly.GetExecutingAssembly()
                        .GetManifestResourceStream("WindowsFormsApplication1.testimage.png")) 
        {
            pictureBox1.Image = Image.FromStream(stream);
        }
相关问题