public static Bitmap ToBitmap(this RawBitmapData rawBitmapData) { Bitmap bitmap = new Bitmap(rawBitmapData.PixelWidth, rawBitmapData.PixelHeight, rawBitmapData.PixelFormat); BitmapData lockedBits = null; try { lockedBits = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, bitmap.PixelFormat); Marshal.Copy(rawBitmapData.RawPixelBytes, 0, lockedBits.Scan0, rawBitmapData.RawPixelBytes.Length); return(bitmap); } catch (Exception) { bitmap?.Dispose(); throw; } finally { if (lockedBits != null) { bitmap.UnlockBits(lockedBits); } } }
public static ByteImage ToByteImageOfY(this RawBitmapData rawBitmapData, Rectangle area) { RawBitmapData rawBitmapData1ByteComponent = rawBitmapData; if (!Is1BytePerComponentFormat(rawBitmapData.PixelFormat)) { using (var bitmap = rawBitmapData.ToBitmap()) { if (bitmap.PixelFormat == PixelFormat.Format24bppRgb) { rawBitmapData1ByteComponent = bitmap.ToRawBitmapData(); } else { using (var bitmap24Rgb = bitmap.ToRgb24()) rawBitmapData1ByteComponent = bitmap24Rgb.ToRawBitmapData(); } } } var data = rawBitmapData1ByteComponent; var r = new ByteImage(rawBitmapData1ByteComponent.PixelWidth, rawBitmapData1ByteComponent.PixelHeight); var yc = new Vector3(66, 129, 25); rawBitmapData1ByteComponent.PerPixelInArea(area, (dx, dy, A, R, G, B) => { Vector3 sv; sv.Z = R; sv.Y = G; sv.X = B; r[dx, dy] = (byte)(((int)(Vector3.Dot(yc, sv) + 128) >> 8) + 16); }); return(r); }
public static RawBitmapData ToRawBitmapData(this Bitmap bitmap) => RawBitmapData.FromBitmap(bitmap);
public static ByteImage ToByteImageOfY(this RawBitmapData rawBitmapData) { return(rawBitmapData.ToByteImageOfY(new Rectangle(0, 0, rawBitmapData.PixelWidth, rawBitmapData.PixelHeight))); }
/// <summary> /// Computes a Digest of raw bitmap data. 8bit per color component format is recommended to avoid unneccessary conversions. /// </summary> /// <param name="rawBitmapData">bitmap image to compute digest against</param> /// <param name="computeArea">section of the image to consider for digest</param> /// <param name="sigma">double value for the deviation for a gaussian filter function</param> /// <param name="gamma">double value for gamma correction on the input image</param> /// <param name="numberOfAngles">int value for the number of angles to consider.</param> /// <returns></returns> public static Digest ComputeRawBitmapDigest(RawBitmapData rawBitmapData, Rectangle computeArea, double sigma = DEFAULT_SIGMA, double gamma = DEFAULT_GAMMA, int numberOfAngles = DEFAULT_NUMBER_OF_ANGLES) { return(ComputeDigest(rawBitmapData.ToByteImageOfY(computeArea), sigma, gamma, numberOfAngles: numberOfAngles)); }
public static ByteImage ToLuminanceImage(this RawBitmapData rawBitmapData) => rawBitmapData.ToLuminanceImage(new Rectangle(0, 0, rawBitmapData.PixelWidth, rawBitmapData.PixelHeight));