Posted By

derekholmes on 12/15/09


Tagged

png ResourceManager


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

vali29


Resource Manager Writing PNG Images


 / Published in: C#
 

PNG Images can break if you use Bitmap.save() you musts first convert to the memory stream.

  1. switch (type)
  2. {
  3. case "jpg":
  4. case "jpeg":
  5. WriteImage(name, type, ImageFormat.Jpeg);
  6. break;
  7. case "gif":
  8. WriteImage(name, type, ImageFormat.Gif);
  9. break;
  10. case "png":
  11. WriteImage(name, type, ImageFormat.Png);
  12. break;
  13. default:
  14. throw new ArgumentException("Invalid Resource Type Specified.");
  15. }
  16.  
  17.  
  18. protected void WriteImage(string name, string type, ImageFormat format)
  19. {
  20. _response.ContentType = "image/" + type;
  21. Bitmap imageData = (Bitmap)Properties.Resources.ResourceManager.GetObject(name);
  22. MemoryStream ms = new MemoryStream();
  23. imageData.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  24. ms.WriteTo(_response.OutputStream);
  25.  
  26. imageData.Dispose();
  27. ms.Close();
  28. }

Report this snippet  

You need to login to post a comment.