2013-04-06 81 views
0

我有一个使用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); 
    } 

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

回答

0

PNG文件添加到您的项目(右键单击从解决方案资源管理项目 - >添加现有项),那么一旦在文件属性添加,设置生成操作:嵌入式的资源。

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

我不能够改变通过属性窗口中的生成动作,我做错了什么?看来我只能在资源上更改生成操作,而不能解决项目。 – user1580598 2013-04-06 03:40:12

+0

我已添加屏幕截图 - 请确保在解决方案资源管理器中选择png文件。你应该得到这个选项.. – 2013-04-06 03:44:17

+0

好的,我得到错误在当前上下文中不存在名称'Assembly',并且找不到Stream。 – user1580598 2013-04-06 03:51:16