public override Image ReadImageData(IPnmDataReader dr, int width, int height) { Image image; try { Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); System.Drawing.Imaging.BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); byte[] data = new byte[height * bitmapdata.Stride]; for (int i = 0; i < height; i++) { dr.Read(data, i * bitmapdata.Stride, width * 3); } System.Runtime.InteropServices.Marshal.Copy(data, 0, bitmapdata.Scan0, data.Length); bitmap.UnlockBits(bitmapdata); image = bitmap; } catch { throw; } finally { dr.Close(); } return(image); }
public override Image ReadImageData(IPnmDataReader dr, int width, int height) { Image image; try { Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); System.Drawing.Imaging.BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); System.Drawing.Imaging.ColorPalette palette = bitmap.Palette; for (int i = 0; i < palette.Entries.Length; i++) { palette.Entries[i] = Color.FromArgb(i, i, i); } bitmap.Palette = palette; byte[] data = new byte[height * bitmapdata.Stride]; for (int j = 0; j < height; j++) { dr.Read(data, j * bitmapdata.Stride, width); } System.Runtime.InteropServices.Marshal.Copy(data, 0, bitmapdata.Scan0, data.Length); bitmap.UnlockBits(bitmapdata); image = bitmap; } catch { throw; } finally { dr.Close(); } return(image); }
public override Image ReadImageData(IPnmDataReader dr, int width, int height) { Image image; try { int count = (dr is ASCIIDataReader) ? width : ((int)Math.Ceiling((double)(((double)width) / 8.0))); Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); System.Drawing.Imaging.BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); System.Drawing.Imaging.ColorPalette palette = bitmap.Palette; palette.Entries[0] = Color.Black; palette.Entries[1] = Color.White; bitmap.Palette = palette; byte[] data = new byte[height * bitmapdata.Stride]; for (int i = 0; i < height; i++) { dr.Read(data, i * bitmapdata.Stride, count); } System.Runtime.InteropServices.Marshal.Copy(data, 0, bitmapdata.Scan0, data.Length); bitmap.UnlockBits(bitmapdata); image = bitmap; } catch { throw; } finally { dr.Close(); } return(image); }
public override Image ReadImageData(IPnmDataReader dr, int width, int height) { Image image; try { Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); System.Drawing.Imaging.BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); byte[] data = new byte[height * bitmapdata.Stride]; for (int i = 0; i < height; i++) { dr.Read(data, i * bitmapdata.Stride, width * 3); } System.Runtime.InteropServices.Marshal.Copy(data, 0, bitmapdata.Scan0, data.Length); bitmap.UnlockBits(bitmapdata); image = bitmap; } catch { throw; } finally { dr.Close(); } return image; }
public override Image ReadImageData(IPnmDataReader dr, int width, int height) { Image image; try { Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); System.Drawing.Imaging.BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); System.Drawing.Imaging.ColorPalette palette = bitmap.Palette; for (int i = 0; i < palette.Entries.Length; i++) { palette.Entries[i] = Color.FromArgb(i, i, i); } bitmap.Palette = palette; byte[] data = new byte[height * bitmapdata.Stride]; for (int j = 0; j < height; j++) { dr.Read(data, j * bitmapdata.Stride, width); } System.Runtime.InteropServices.Marshal.Copy(data, 0, bitmapdata.Scan0, data.Length); bitmap.UnlockBits(bitmapdata); image = bitmap; } catch { throw; } finally { dr.Close(); } return image; }
public override Image ReadImageData(IPnmDataReader dr, int width, int height) { Image image; try { int count = (dr is ASCIIDataReader) ? width : ((int)Math.Ceiling((double)(((double)width) / 8.0))); Bitmap bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); System.Drawing.Imaging.BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); System.Drawing.Imaging.ColorPalette palette = bitmap.Palette; palette.Entries[0] = Color.Black; palette.Entries[1] = Color.White; bitmap.Palette = palette; byte[] data = new byte[height * bitmapdata.Stride]; for (int i = 0; i < height; i++) { dr.Read(data, i * bitmapdata.Stride, count); } System.Runtime.InteropServices.Marshal.Copy(data, 0, bitmapdata.Scan0, data.Length); bitmap.UnlockBits(bitmapdata); image = bitmap; } catch { throw; } finally { dr.Close(); } return image; }