public LinearAccessByteImage readImage() { if (openMode == OpenMode.WRITE) { throw new Exception("Attempting to read in write mode."); } if (readFrames == _header.imageCount) { // Already read all there is return(null); } LinearAccessByteImage result = new LinearAccessByteImage(reader.ReadBytes((int)_header.singleImageByteSize), (int)_header.width * 3, (int)_header.width, (int)_header.height, 3); readFrames++; return(result); }
public static Bitmap ByteArrayToBitmap(LinearAccessByteImage byteImage) { Bitmap myBitmap = new Bitmap(byteImage.width, byteImage.height, byteImage.originalPixelFormat); Rectangle rect = new Rectangle(0, 0, myBitmap.Width, myBitmap.Height); System.Drawing.Imaging.BitmapData bmpData = myBitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, myBitmap.PixelFormat); bmpData.Stride = byteImage.originalStride; IntPtr ptr = bmpData.Scan0; byte[] originalDataReconstruction = byteImage.getOriginalDataReconstruction(); System.Runtime.InteropServices.Marshal.Copy(originalDataReconstruction, 0, ptr, originalDataReconstruction.Length); myBitmap.UnlockBits(bmpData); return(myBitmap); }
public void writeImage(LinearAccessByteImage inputImage) { if (isFinalized) { throw new Exception("Attempting to change finalized file."); } if (openMode == OpenMode.READ) { throw new Exception("Attempting to write in read mode."); } byte[] buffer = new byte[_header.singleImageByteSize]; for (int y = 0; y < _header.height; y++) { for (int x = 0; x < _header.width; x++) { buffer[y * _header.width * 3 + x * 3] = (byte)(128 + inputImage.imageData[y * _header.width * 3 + x * 3]); buffer[y * _header.width * 3 + x * 3 + 1] = (byte)(128 + inputImage.imageData[y * _header.width * 3 + x * 3 + 1]); buffer[y * _header.width * 3 + x * 3 + 2] = (byte)(128 + inputImage.imageData[y * _header.width * 3 + x * 3 + 2]); } } writer.Write(buffer); }