0

I have a program that uses pngs and when I put them in the resources they are downgraded to a bitmap that only supports 24 bit color. Is there a way I can keep the image quality from being screwed up?

   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);
    }

I want to make sure the image quality doesn't change, do I possibly just host the image on a website? Or possibly include it in a folder without putting it into resources?

4

1 回答 1

0

将 png 文件添加到您的项目(从解决方案资源管理器中右键单击您的项目 -> 添加现有项目),然后在文件属性中添加后,将构建操作设置为:嵌入式资源。

在此处输入图像描述

然后加载您的图像

    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);
        }
于 2013-04-06T03:28:44.300 回答