Esempio n. 1
0
        private static BitmapFrame CreateBitmapVersionOne(byte[] bitmapVersionOneBytes,
            BITMAPINFOHEADER bitmapVersionOneHeader)
        {
            var fileHeaderSize = Marshal.SizeOf(typeof (BITMAPFILEHEADER));
            var infoHeaderSize = bitmapVersionOneHeader.biSize;
            var fileSize = fileHeaderSize + bitmapVersionOneHeader.biSize + bitmapVersionOneHeader.biSizeImage;

            var fileHeader = new BITMAPFILEHEADER
            {
                bfType = BITMAPFILEHEADER.BM,
                bfSize = fileSize,
                bfReserved1 = 0,
                bfReserved2 = 0,
                bfOffBits = fileHeaderSize + infoHeaderSize + bitmapVersionOneHeader.biClrUsed*4
            };

            var fileHeaderBytes = GeneralApi.StructureToByteArray(fileHeader);

            var bitmapStream = new MemoryStream();
            bitmapStream.Write(fileHeaderBytes, 0, fileHeaderSize);
            bitmapStream.Write(bitmapVersionOneBytes, 0, bitmapVersionOneBytes.Length);
            bitmapStream.Seek(0, SeekOrigin.Begin);

            var bitmap = BitmapFrame.Create(bitmapStream);
            return bitmap;
        }
Esempio n. 2
0
 byte[] HandleBitmapVersionOne(byte[] bitmapVersionOneBytes, BITMAPINFOHEADER bitmapVersionOneHeader)
 {
     var bitmap = CreateBitmapVersionOne(bitmapVersionOneBytes, bitmapVersionOneHeader);
     return imagePersistenceService.ConvertBitmapSourceToByteArray(bitmap);
 }