System.Drawing.Bitmap.RotateFlip C# (CSharp) Method

RotateFlip() private method

private RotateFlip ( RotateFlipType rotateFlipType ) : void
rotateFlipType RotateFlipType
return void
        internal void RotateFlip(RotateFlipType rotateFlipType)
        {
            CGAffineTransform rotateFlip = CGAffineTransform.MakeIdentity();

            int width, height;
            width = (int)NativeCGImage.Width;
            height = (int)NativeCGImage.Height;

            switch (rotateFlipType)
            {
                //			case RotateFlipType.RotateNoneFlipNone:
                //			//case RotateFlipType.Rotate180FlipXY:
                //				rotateFlip = GeomUtilities.CreateRotateFlipTransform (b.Width, b.Height, 0, false, false);
                //				break;
                case RotateFlipType.Rotate90FlipNone:
                //case RotateFlipType.Rotate270FlipXY:
                rotateFlip = GeomUtilities.CreateRotateFlipTransform (ref width, ref height, 90, false, false);
                break;
                case RotateFlipType.Rotate180FlipNone:
                //case RotateFlipType.RotateNoneFlipXY:
                rotateFlip = GeomUtilities.CreateRotateFlipTransform (ref width, ref height, 0, true, true);
                break;
                case RotateFlipType.Rotate270FlipNone:
                //case RotateFlipType.Rotate90FlipXY:
                rotateFlip = GeomUtilities.CreateRotateFlipTransform (ref width, ref height, 270, false, false);
                break;
                case RotateFlipType.RotateNoneFlipX:
                //case RotateFlipType.Rotate180FlipY:
                rotateFlip = GeomUtilities.CreateRotateFlipTransform (ref width, ref height, 0, true, false);
                break;
                case RotateFlipType.Rotate90FlipX:
                //case RotateFlipType.Rotate270FlipY:
                rotateFlip = GeomUtilities.CreateRotateFlipTransform (ref width, ref height, 90, true, false);
                break;
                case RotateFlipType.Rotate180FlipX:
                //case RotateFlipType.RotateNoneFlipY:
                rotateFlip = GeomUtilities.CreateRotateFlipTransform (ref width, ref height, 0, false, true);
                break;
                case RotateFlipType.Rotate270FlipX:
                //case RotateFlipType.Rotate90FlipY:
                rotateFlip = GeomUtilities.CreateRotateFlipTransform (ref width, ref height, 270, true, false);
                break;
            }

            var format = GetBestSupportedFormat (pixelFormat);
            var bitmapContext = CreateCompatibleBitmapContext (width, height, format);

            bitmapContext.ConcatCTM (rotateFlip);

            bitmapContext.DrawImage (new CGRect (0, 0, NativeCGImage.Width, NativeCGImage.Height), NativeCGImage);

            int size = (int)(bitmapContext.BytesPerRow * bitmapContext.Height);
            var provider = new CGDataProvider (bitmapContext.Data, size, true);

            // If the width or height is not the seme we need to switch the dpiHeight and dpiWidth
            // We should be able to get around this with set resolution later.
            if (NativeCGImage.Width != width || NativeCGImage.Height != height)
            {
                var temp = dpiWidth;
                dpiHeight = dpiWidth;
                dpiWidth = temp;
            }

            NativeCGImage = new CGImage ((int)bitmapContext.Width, (int)bitmapContext.Height, (int)bitmapContext.BitsPerComponent,
                                         (int)bitmapContext.BitsPerPixel, (int)bitmapContext.BytesPerRow,
                                         bitmapContext.ColorSpace,
                                         bitmapContext.AlphaInfo,
                                         provider, null, true, CGColorRenderingIntent.Default);

            physicalDimension.Width = (float)width;
            physicalDimension.Height = (float)height;

            physicalSize = new SizeF (physicalDimension.Width, physicalDimension.Height);
            physicalSize.Width *= ConversionHelpers.MS_DPI / dpiWidth;
            physicalSize.Height *= ConversionHelpers.MS_DPI / dpiHeight;

            // In windows the RawFormat is changed to MemoryBmp to show that the image has changed.
            rawFormat = ImageFormat.MemoryBmp;

            // Set our transform for this image for the new height
            imageTransform = new CGAffineTransform(1, 0, 0, -1, 0, height);
        }

Usage Example

Example #1
1
        public void AddFrame(Bitmap bmp)
        {
            bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

            BitmapData bmpDat = bmp.LockBits(
                new Rectangle(0, 0, bmp.Width, bmp.Height),
                ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);

            if (countFrames == 0)
            {
                this.stride = (UInt32)bmpDat.Stride;
                this.width = bmp.Width;
                this.height = bmp.Height;
                CreateStream();
            }

            int result = AviReadingMethods.AVIStreamWrite(aviStream,
                countFrames, 1,
                bmpDat.Scan0,
                (Int32)(stride * height),
                0, 0, 0);

            if (result != 0)
            {
                throw new Exception("Problem podczas otwierania pliku AVI" + result.ToString());
            }

            bmp.UnlockBits(bmpDat);
            countFrames++;
        }
All Usage Examples Of System.Drawing.Bitmap::RotateFlip