public static void writeToFile(COMMON.ByteMatrix matrix, System.Drawing.Imaging.ImageFormat format, string file) { System.Drawing.Imaging.EncoderParameters eps = new System.Drawing.Imaging.EncoderParameters(); eps.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality,100L); Bitmap bmap = toBitmap(matrix); bmap.Save(file,format); }
public static Bitmap toBitmap(COMMON.ByteMatrix matrix) { int width = matrix.Width; int height = matrix.Height; Bitmap bmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { bmap.SetPixel(x, y, matrix.get_Renamed(x, y) != -1 ? ColorTranslator.FromHtml("0xFF000000") : ColorTranslator.FromHtml("0xFFFFFFFF")); } } return bmap; }
public static void WriteToFile(COMMON.ByteMatrix matrix, System.Drawing.Imaging.ImageFormat format, string file, bool isAppendImage) { Bitmap bmap = toBitmap(matrix); if (isAppendImage) { Graphics g = Graphics.FromImage(bmap); string f = string.Concat(System.Web.HttpContext.Current.Server.MapPath("."), "\\include\\append.png"); Util.AddWatermarkImage(g, f, "CENTER", 300, 300); } bmap.Save(file, format); }
public static byte[] GetBytes(COMMON.ByteMatrix matrix, System.Drawing.Imaging.ImageFormat format, bool isAppendImage) { Bitmap bmap = toBitmap(matrix); if (isAppendImage) { Graphics g = Graphics.FromImage(bmap); string f = string.Concat(System.Web.HttpContext.Current.Server.MapPath("."), "\\include\\append.png"); Util.AddWatermarkImage(g, f, "CENTER", 300, 300); } System.IO.MemoryStream ms = new System.IO.MemoryStream(); bmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); bmap.Dispose(); return ms.ToArray(); }
public static void Display(System.Web.HttpResponse response, COMMON.ByteMatrix matrix, System.Drawing.Imaging.ImageFormat format, bool isAppendImage) { response.ClearContent(); response.ContentType = "image/Jpeg"; response.BinaryWrite(GetBytes(matrix, format, isAppendImage)); response.End(); }
private Bitmap toBitmap(COMMON.ByteMatrix matrix, float fltDPIX, float fltDPIY) { int width = matrix.Width; int height = matrix.Height; Bitmap bmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); bmap.SetResolution(fltDPIX, fltDPIY);//设置图片象素 for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { bmap.SetPixel(x, y, matrix.get_Renamed(x, y) != -1 ? ColorTranslator.FromHtml("0xFF000000") : ColorTranslator.FromHtml("0xFFFFFFFF")); } } return bmap; }