public Bitmap Convert(Pix pix, bool includeAlpha = false) { var pixelFormat = GetPixelFormat(pix); var depth = pix.Depth; var img = new Bitmap(pix.Width, pix.Height, pixelFormat); if (pix.XRes > 1 && pix.YRes > 1) { img.SetResolution(pix.XRes, pix.YRes); } BitmapData imgData = null; PixData pixData = null; try { // TODO: Set X and Y resolution // transfer pixel data if ((pixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed) { TransferPalette(pix, img); } // transfer data pixData = pix.GetData(); imgData = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.WriteOnly, pixelFormat); if (depth == 32) { TransferData32(pixData, imgData, includeAlpha ? 0 : 255); } else if (depth == 16) { TransferData16(pixData, imgData); } else if (depth == 8) { TransferData8(pixData, imgData); } else if (depth == 1) { TransferData1(pixData, imgData); } return(img); } catch (Exception) { img.Dispose(); throw; } finally { if (imgData != null) { img.UnlockBits(imgData); } } }
public Bitmap Convert(Pix pix, bool includeAlpha = false) { var pixelFormat = this.GetPixelFormat(pix); var depth = pix.Depth; var img = new Bitmap(pix.Width, pix.Height, pixelFormat); BitmapData imgData = null; try { // TODO: Set X and Y resolution // transfer pixel data if ((pixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed) { this.TransferPalette(pix, img); } // transfer data var pixData = pix.GetData(); imgData = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.WriteOnly, pixelFormat); switch (depth) { case 32: this.TransferData32(pixData, imgData, includeAlpha ? 0 : 255); break; case 16: this.TransferData16(pixData, imgData); break; case 8: this.TransferData8(pixData, imgData); break; case 1: this.TransferData1(pixData, imgData); break; } return(img); } catch (Exception) { img.Dispose(); throw; } finally { if (imgData != null) { img.UnlockBits(imgData); } } }
public Bitmap Convert(Pix pix, bool includeAlpha = false) { var pixelFormat = GetPixelFormat(pix); var depth = pix.Depth; var img = new Bitmap(pix.Width, pix.Height, pixelFormat); BitmapData imgData = null; PixData pixData = null; try { // TODO: Set X and Y resolution // transfer pixel data if ((pixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed) { TransferPalette(pix, img); } // transfer data pixData = pix.GetData(); imgData = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.WriteOnly, pixelFormat); if (depth == 32) { TransferData32(pixData, imgData, includeAlpha ? 0 : 255); } else if (depth == 16) { TransferData16(pixData, imgData); } else if (depth == 8) { TransferData8(pixData, imgData); } else if (depth == 1) { TransferData1(pixData, imgData); } return img; } catch (Exception) { img.Dispose(); throw; } finally { if (imgData != null) { img.UnlockBits(imgData); } } }