public CanonBitmap readBitmap(CanonHeader header, int width, int height) { CanonBitmap bmp; if (width <= 0 || height <= 0) { throw new BitmapSizeException("width and height must be > 0"); } int size = width * height; int padding = (size + CanonHeader.SIZE) % (byte)_byteAlign == 0 ? 0 : (byte)_byteAlign - (size + CanonBitmapHeader.SIZE) % (byte)_byteAlign; //Console.WriteLine("trying to read {0} bytes, {0}%{1}={2} -> padding {3} bytes (pad_to {4})", // size, CanonBitmapHeader.SIZE, (size + CanonBitmapHeader.SIZE) % (byte)_byteAlign, padding, _byteAlign); byte[] data = new byte[size + padding]; if (_dataFile.Read(data, 0, size + padding) != (size + padding)) { throw new EndOfStreamException("cannot read the whole bitmap data (EOF?)"); } bmp = new CanonBitmap(header, data); bmp.Width = width; bmp.Height = height; return(bmp); }
public CanonBitmap(byte[] data, long origin) { if (data.Length <= 0) { throw new Exception("no data"); } if (data.Length < CanonBitmapHeader.SIZE) { throw new Exception("too few data (no header)"); } byte[] headerData = new byte[CanonBitmapHeader.SIZE]; Array.Copy(data, headerData, CanonBitmapHeader.SIZE); this.header = new CanonBitmapHeader(headerData, origin); byte[] imageData = new byte[data.Length - CanonBitmapHeader.SIZE]; Array.Copy(data, CanonBitmapHeader.SIZE, imageData, 0, data.Length - CanonBitmapHeader.SIZE); this.data = imageData; if (this.header.Value1 <= 0) { throw new Exception("invalid width (<=0)"); } this.width = this.header.Value1; this.height = (byte)(this.data.Length / this.width); }
/// <summary> /// Read the bitmap on the current position and adds the passed header. /// </summary> /// <param name="header"></param> /// <returns></returns> public CanonBitmap readBitmap(CanonHeader header) { if (header is CanonBitmapHeader) { return(readBitmap(header, header.Value1, DEFAULT_HEIGHT)); } else if (header is CanonBigBitmapHeader) { return(readBitmap(header, header.Value1, header.Value2)); } // should not happen return(null); }
public CanonBitmap(CanonHeader header, byte[] data) { if (header == null) { throw new NullReferenceException("header must not be null"); } if (data.Length <= 0) { throw new Exception("no data"); } if (header.Value1 <= 0) { throw new Exception("invalid width (<=0)"); } this.header = header; this.data = data; this.Width = header.Value1; this.Height = (byte)(data.Length / this.Width); }
private void printBitmapHeader(CanonHeader header) { string hInfo = "header hex / dec: {0:X2} {1:X2} / {0} {1}"; lblBitmapHeader.Text = String.Format(hInfo, header.Value1, header.Value2); }