2011-04-20 65 views
1

您好目前我使用C#,我有一个图像的像素数据,我想要转换为Jpg/png格式?你可以建议我任何库或做.net提供任何压缩API?将像素数据压缩为jpg/png格式

+0

可能重复的[骨形态发生蛋白,以JPG/PNG在C#(http://stackoverflow.com/questions/41665/bmp-to-jpg-png-in-c) – Oliver 2011-04-20 12:14:13

回答

0

尝试这种情况:

 //example 1: converting from bitmap 
     Bitmap myImage1 = new Bitmap(@"C:\myimage1.bmp"); 

     myImage1.Save(@"C:\myimage1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); 
     myImage1.Save(@"C:\myimage1.png", System.Drawing.Imaging.ImageFormat.Png); 


     //example 2: converting from pixels 
     Bitmap myImage2 = new Bitmap(10, 10); 

     //for loop to set some pixels 
     for (int x=0;x<10;x++) 
      for (int y=0;y<10;y++) 
       myImage2.SetPixel(x,y,Color.Blue); 

     myImage2.Save(@"C:\myimage2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); 
     myImage2.Save(@"C:\myimage2.png", System.Drawing.Imaging.ImageFormat.Png);