Пример #1
0
 /// <summary>
 /// Create a new BitmapSource from the given RgbData
 /// </summary>
 /// <param name="rgbData">the source RgbData</param>
 /// <returns>a BitmapSource</returns>
 public static BitmapSource createBitmapSource(RgbData rgbData)
 {
     BitmapSource bitmapSource = BitmapSource.Create(rgbData.pixelWidth,
                                                 rgbData.pixelHeight,
                                                 rgbData.dpiX,
                                                 rgbData.dpiY,
                                                 rgbData.pixelFormat,
                                                 null,
                                                 rgbData.rawRgbByteArray,
                                                 rgbData.stride);
     return bitmapSource;
 }
Пример #2
0
        /// <summary>
        /// This method returns the RgbData struct representing the given BitmapSource
        /// </summary>
        /// <param name="bitmapSource">the target BitmapSource</param>
        /// <returns>RgbData representing the given BitmapSource</returns>
        public static RgbData getRgbData(BitmapSource bitmapSource)
        {
            RgbData rgbData = new RgbData();
            rgbData.stride = bitmapSource.PixelWidth * ((bitmapSource.Format.BitsPerPixel + 7) / 8);
            rgbData.dataLength = rgbData.stride * bitmapSource.PixelHeight;
            rgbData.pixelWidth = bitmapSource.PixelWidth;
            rgbData.pixelHeight = bitmapSource.PixelHeight;
            rgbData.dpiX = bitmapSource.DpiX;
            rgbData.dpiY = bitmapSource.DpiY;
            rgbData.pixelFormat = bitmapSource.Format;
            rgbData.rawRgbByteArray = new byte[rgbData.dataLength];

            bitmapSource.CopyPixels(rgbData.rawRgbByteArray, rgbData.stride, 0);

            return rgbData;
        }