Exemple #1
0
        /// <summary>
        /// Вращение изображения
        /// </summary>
        /// <param name="originalImage"></param>
        /// <param name="angle"></param>
        /// <returns></returns>
        public static IImage SaveRortatedIImage(IImage originalImage, RotationAngle angle)
        {
            GDI.IImage rThumbImage;
            ImageInfo  imageInfo;

            GDI.IBitmapImage iBitmapImage;
            originalImage.GetImageInfo(out imageInfo);
            uint width  = imageInfo.Width;
            uint height = imageInfo.Height;

            ImagingFactory.CreateBitmapFromImage((GDI.IImage)originalImage, width, height,
                                                 PixelFormatID.PixelFormat24bppRGB,
                                                 GDI.InterpolationHint.InterpolationHintDefault,
                                                 out iBitmapImage);
            Bitmap rotatedBitmap = ImageUtils.Rotate(ImageUtils.IBitmapImageToBitmap(iBitmapImage as IBitmapImage), angle);
            var    mStream       = new MemoryStream();

            rotatedBitmap.Save(mStream, ImageFormat.Jpeg);
            rotatedBitmap.Dispose();
            var bufSize = (uint)mStream.Length;

            byte[] buffer = mStream.GetBuffer();

            IntPtr bytes = Marshal.AllocHGlobal(buffer.Length);

            Marshal.Copy(buffer, 0, bytes, buffer.Length);
            ImagingFactory.CreateImageFromBuffer(bytes, (uint)buffer.Length, (GDI.BufferDisposalFlag)BufferDisposalFlag.BufferDisposalFlagGlobalFree, out rThumbImage);

            Marshal.FinalReleaseComObject(originalImage);
            return((IImage)rThumbImage);
        }
Exemple #2
0
        /// <summary>
        /// Масштабирование изображения
        /// </summary>
        /// <param name="originalImage"></param>
        /// <param name="maxSize">Размер стороны квадрата в который нужно вписать изображение</param>
        /// <returns></returns>
        public static IImage ScaleIImage(IImage originalImage, uint maxSize)
        {
            IImage    thumbImage;
            ImageInfo imageInfo;

            originalImage.GetImageInfo(out imageInfo);

            uint width  = imageInfo.Width;
            uint height = imageInfo.Height;

            if (height > maxSize && width < maxSize ||
                (height > maxSize && width > maxSize && height > width))
            {
                width  = (width * maxSize) / height;
                height = maxSize;
            }
            else if (height < maxSize && width > maxSize ||
                     (height > maxSize && width > maxSize && height < width))
            {
                height = (height * maxSize) / width;
                width  = maxSize;
            }
            else if (height > maxSize && width > maxSize && height == width)
            {
                height = width = maxSize;
            }

            originalImage.GetThumbnail(width, height, out thumbImage);
            return(thumbImage);
        }
Exemple #3
0
        /// <summary>
        /// Создание Bitmap из IImage
        /// </summary>
        /// <param name="img">Исходное изображение IImage</param>
        /// <returns>Bitmap</returns>
        public static Bitmap CreateBitmapFromIImage(IImage img)
        {
            GDI.IBitmapImage bmp;
            ImageInfo        ii;

            img.GetImageInfo(out ii);
            ImagingFactory.CreateBitmapFromImage((GDI.IImage)img, ii.Width, ii.Height, PixelFormatID.PixelFormat24bppRGB, GDI.InterpolationHint.InterpolationHintBilinear, out bmp);
            return(ImageUtils.IBitmapImageToBitmap((IBitmapImage)bmp));
        }
Exemple #4
0
        /// <summary>
        /// Сохранение изображения
        /// </summary>
        /// <param name="image"></param>
        /// <param name="fileName"></param>
        public static void SaveIImage(IImage image, string fileName)
        {
            ImageInfo imageInfo;

            GDI.IBitmapImage iBitmapImage;
            image.GetImageInfo(out imageInfo);
            uint width  = imageInfo.Width;
            uint height = imageInfo.Height;

            ImagingFactory.CreateBitmapFromImage((GDI.IImage)image, width, height,
                                                 PixelFormatID.PixelFormat24bppRGB,
                                                 GDI.InterpolationHint.InterpolationHintDefault,
                                                 out iBitmapImage);
            Bitmap bitmap = ImageUtils.IBitmapImageToBitmap((IBitmapImage)iBitmapImage);

            bitmap.Save(fileName, ImageFormat.Jpeg);
            bitmap.Dispose();
        }