Пример #1
0
        public static int GetArrayBufferSize(Array buffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            int elementSize = WicUtility.GetElementSize(buffer);

            return(elementSize * buffer.Length);
        }
Пример #2
0
        public static float ComputeDownScale(this IWICBitmapSource imageSource, int targetSize, Func <float, float, float> sizeSelector = null)
        {
            if (imageSource == null)
            {
                throw new ArgumentNullException("imageSource");
            }
            int width;
            int height;

            imageSource.GetSize(out width, out height);
            return(WicUtility.ComputeDownScale(width, height, targetSize, sizeSelector));
        }
Пример #3
0
        public static int GetArrayStride(Array buffer, int width, int height)
        {
            if (width <= 0)
            {
                throw new ArgumentOutOfRangeException("width");
            }
            if (height <= 0)
            {
                throw new ArgumentOutOfRangeException("height");
            }
            int elementSize = WicUtility.GetElementSize(buffer);

            return(elementSize * width);
        }
Пример #4
0
        public static IWICBitmap CreateBitmapFromBlob(this IWICImagingFactory factory, Array blob, int width, int height, int stride, Guid imageFormat)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }
            if (blob == null)
            {
                throw new ArgumentNullException("blob");
            }
            int        arrayBufferSize = WicUtility.GetArrayBufferSize(blob);
            IWICBitmap result;

            using (PinHelper pinHelper = new PinHelper(blob))
            {
                factory.CreateBitmapFromMemory(width, height, ref imageFormat, stride, arrayBufferSize, pinHelper.Addr, out result);
            }
            return(result);
        }
Пример #5
0
        public static void FillBlobFromBitmapSource(this IWICBitmapSource bitmap, Array blob)
        {
            if (bitmap == null)
            {
                throw new ArgumentNullException("bitmap");
            }
            if (blob == null)
            {
                throw new ArgumentNullException("blob");
            }
            WICRect wicrect = default(WICRect);

            bitmap.GetSize(out wicrect.Width, out wicrect.Height);
            int arrayStride     = WicUtility.GetArrayStride(blob, wicrect.Width, wicrect.Height);
            int arrayBufferSize = WicUtility.GetArrayBufferSize(blob);

            using (PinHelper pinHelper = new PinHelper(blob))
            {
                bitmap.CopyPixels(ref wicrect, arrayStride, arrayBufferSize, pinHelper.Addr);
            }
        }