Example #1
0
        public static async Task RotateAsync(StorageFile sourcefile, RotationAngle angle)
        {
            using (IRandomAccessStream sourceStream = await sourcefile.OpenAsync(FileAccessMode.ReadWrite))
            {
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(sourceStream);

                BitmapEncoder encoder = await BitmapEncoder.CreateForTranscodingAsync(sourceStream, decoder);

                switch (angle)
                {
                case RotationAngle.None:
                    break;

                case RotationAngle.Clockwise90Degrees:
                    encoder.BitmapTransform.Rotation = BitmapRotation.Clockwise90Degrees;
                    break;

                case RotationAngle.Clockwise180Degrees:
                    encoder.BitmapTransform.Rotation = BitmapRotation.Clockwise180Degrees;
                    break;

                case RotationAngle.Clockwise270Degrees:
                    encoder.BitmapTransform.Rotation = BitmapRotation.Clockwise270Degrees;
                    break;

                default:
                    break;
                }
                // Flush the data to file.
                await encoder.FlushAsync();
            }
        }
Example #2
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);
        }
Example #3
0
        /// <summary>
        /// Заключительная обработка избражения: вращение на заданный угол
        /// </summary>
        /// <param name="file"></param>
        /// <param name="angle"></param>
        public static void PostProcessImageFile(string file, RotationAngle angle)
        {
            GDI.IImage       image;
            GDI.IBitmapImage newIBitmapImage;
            Bitmap           newBitmap;

            GDI.ImageInfo newImageInfo;

            if (angle != RotationAngle.Zero)
            {
                ImagingFactory.CreateImageFromFile(file, out image);

                image.GetImageInfo(out newImageInfo);

                ImagingFactory.CreateBitmapFromImage(image, newImageInfo.Width, newImageInfo.Height, PixelFormatID.PixelFormat24bppRGB, DefaultInterpolation, out newIBitmapImage);

                newBitmap = ImageUtils.IBitmapImageToBitmap((IBitmapImage)newIBitmapImage);

                newBitmap = ImageUtils.Rotate(newBitmap, angle);

                Marshal.FinalReleaseComObject(image);

                newBitmap.Save(file, ImageFormat.Jpeg);

                Marshal.FinalReleaseComObject(image);
                Marshal.FinalReleaseComObject(newIBitmapImage);
                newBitmap.Dispose();
            }
        }
Example #4
0
        /// <summary>
        /// Rotate and/or flip bitmap
        /// </summary>
        /// <param name="bitmap">Image</param>
        /// <param name="type">Operation</param>
        /// <returns>Modified bitmap</returns>
        static public Bitmap RotateFlip(Bitmap bitmap, RotationAngle angle, FlipAxis axis)
        {
            if (bitmap == null)
            {
                throw new ArgumentNullException();
            }

            IBitmapImage image = BitmapToIImageBitmap(bitmap);

            try
            {
                IBitmapImage    imageBitmap = BitmapToIImageBitmap(bitmap);
                IBasicBitmapOps ops         = (IBasicBitmapOps)imageBitmap;
                if (angle != 0)
                {
                    ops.Rotate((float)angle, InterpolationHint.InterpolationHintDefault, out imageBitmap);
                    Marshal.FinalReleaseComObject(ops);
                    ops = (IBasicBitmapOps)imageBitmap;
                }
                if (axis != FlipAxis.None)
                {
                    ops.Flip((axis & FlipAxis.X) == FlipAxis.X, (axis & FlipAxis.Y) == FlipAxis.Y, out imageBitmap);
                    Marshal.FinalReleaseComObject(ops);
                    ops = (IBasicBitmapOps)imageBitmap;
                }
                return(IBitmapImageToBitmap(imageBitmap));
            }
            finally
            {
                Marshal.FinalReleaseComObject(image);
            }
        }
        public static Vector3 CameraToRealWorld(float x, float y, float z, RotationAngle imageRotation = RotationAngle.Rotation0, bool isMirrored = false)
        {
            var isInverted = IsInverted(imageRotation);

            var(rx, ry) = isInverted ? (y, x) : (x, y);
            return(new Vector3(IsXReversed(imageRotation, isMirrored) ? -rx : rx, IsYReversed(imageRotation, isMirrored) ? -ry : ry, -z));
        }
 /// <summary>
 ///   Convert from camera coordinates to local coordinates in Unity.
 /// </summary>
 /// <param name="rectangle">Rectangle to get a point inside</param>
 /// <param name="x">X in camera coordinates</param>
 /// <param name="y">Y in camera coordinates</param>
 /// <param name="z">Z in camera coordinates</param>
 /// <param name="focalLength">Normalized focal lengths in NDC space</param>
 /// <param name="principalPoint">Normalized principal point in NDC space</param>
 /// <param name="zScale">Ratio of Z values in camera coordinates to local coordinates in Unity</param>
 /// <param name="imageRotation">
 ///   Counterclockwise rotation angle of the input image in the image coordinate system.
 ///   In the local coordinate system, this value will often represent a clockwise rotation angle.
 /// </param>
 /// <param name="isMirrored">Set to true if the original coordinates is mirrored</param>
 public static Vector3 CameraToPoint(UnityEngine.Rect rectangle, float x, float y, float z,
                                     Vector2 focalLength, Vector2 principalPoint,
                                     float zScale, RotationAngle imageRotation = RotationAngle.Rotation0, bool isMirrored = false)
 {
     return(CameraToLocalPoint(x, y, z, rectangle.xMin, rectangle.xMax, rectangle.yMin, rectangle.yMax, focalLength.x, focalLength.y, principalPoint.x, principalPoint.y,
                               zScale, imageRotation, isMirrored));
 }
Example #7
0
        public static void CustomSaveScaledImage(string iFile, string oFile, int maxLinearSize, RotationAngle angle)
        {
            GDI.IImage image;
            GDI.IBitmapImage newIBitmapImage;
            Bitmap newBitmap;
            GDI.ImageInfo newImageInfo;

            ImagingFactory.CreateImageFromFile(iFile, out image);

            image.GetImageInfo(out newImageInfo);

            Size oSize;

            if (!(newImageInfo.Width <= maxLinearSize && newImageInfo.Height <= maxLinearSize))
                GetSizeByMaxLinearSize(new Size((int) newImageInfo.Width, (int) newImageInfo.Height), maxLinearSize, out oSize);
            else
                oSize = new Size((int)newImageInfo.Width, (int)newImageInfo.Height);

            ImagingFactory.CreateBitmapFromImage(image, (uint)oSize.Width, (uint)oSize.Height, PixelFormatID.PixelFormat24bppRGB, DefaultInterpolation, out newIBitmapImage);

            newBitmap = ImageUtils.IBitmapImageToBitmap((IBitmapImage)newIBitmapImage);

            if (angle != RotationAngle.Zero)
            {
                newBitmap = ImageUtils.Rotate(newBitmap, angle);
            }

            Marshal.FinalReleaseComObject(image);
            Marshal.FinalReleaseComObject(newIBitmapImage);

            newBitmap.Save(oFile, ImageFormat.Jpeg);

            newBitmap.Dispose();
        }
Example #8
0
        /// <summary>
        /// Returns true if ImageRotateParameters instances are equal
        /// </summary>
        /// <param name="input">Instance of ImageRotateParameters to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(ImageRotateParameters input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     FileId == input.FileId ||
                     (FileId != null &&
                      FileId.Equals(input.FileId))
                     ) &&
                 (
                     PageRange == input.PageRange ||
                     (PageRange != null &&
                      PageRange.Equals(input.PageRange))
                 ) &&
                 (
                     RotationAngle == input.RotationAngle ||
                     RotationAngle.Equals(input.RotationAngle)
                 ) &&
                 (
                     FlipHorizontally == input.FlipHorizontally ||
                     FlipHorizontally.Equals(input.FlipHorizontally)
                 ) &&
                 (
                     FlipVertically == input.FlipVertically ||
                     FlipVertically.Equals(input.FlipVertically)
                 ));
        }
Example #9
0
 public virtual void SetRotate(RotationAngle angle)
 {
     if (IsDirectBinding)
     {
         if (IntPtr.Size == 8)
         {
             global::ApiDefinition.Messaging.void_objc_msgSend_UInt64(this.Handle, Selector.GetHandle("setRotate:"), (UInt64)angle);
         }
         else
         {
             global::ApiDefinition.Messaging.void_objc_msgSend_UInt32(this.Handle, Selector.GetHandle("setRotate:"), (UInt32)angle);
         }
     }
     else
     {
         if (IntPtr.Size == 8)
         {
             global::ApiDefinition.Messaging.void_objc_msgSendSuper_UInt64(this.SuperHandle, Selector.GetHandle("setRotate:"), (UInt64)angle);
         }
         else
         {
             global::ApiDefinition.Messaging.void_objc_msgSendSuper_UInt32(this.SuperHandle, Selector.GetHandle("setRotate:"), (UInt32)angle);
         }
     }
 }
        /// <summary>
        ///   Returns a <see cref="Vector3" /> array which represents a rectangle's vertices.
        ///   They are in clockwise order, starting from the coordinate that was in the bottom-left.
        /// </summary>
        /// <remarks>
        ///   Z values are always zero.
        /// </remarks>
        /// <param name="rectangle">Rectangle to get a point inside</param>
        /// <param name="normalizedXMin">Normalized leftmost X value</param>
        /// <param name="normalizedYMin">Normalized topmost Y value</param>
        /// <param name="normalizedWidth">Normalized width</param>
        /// <param name="normalizedHeight">Normalized height</param>
        /// <param name="imageRotation">
        ///   Counterclockwise rotation angle of the input image in the image coordinate system.
        ///   In the local coordinate system, this value will often represent a clockwise rotation angle.
        /// </param>
        /// <param name="isMirrored">Set to true if the original coordinates is mirrored</param>
        public static Vector3[] ImageNormalizedToRectVertices(UnityEngine.Rect rectangle, float normalizedXMin, float normalizedYMin, float normalizedWidth, float normalizedHeight,
                                                              RotationAngle imageRotation = RotationAngle.Rotation0, bool isMirrored = false)
        {
            var p = ImageNormalizedToPoint(rectangle, normalizedXMin, normalizedYMin + normalizedHeight, imageRotation, isMirrored);
            var q = ImageNormalizedToPoint(rectangle, normalizedXMin + normalizedWidth, normalizedYMin, imageRotation, isMirrored);

            return(GetRectVertices(p, q));
        }
        /// <summary>
        ///   Returns a <see cref="Vector3" /> array which represents a rectangle's vertices.
        ///   They are in clockwise order, starting from the coordinate that was in the bottom-left.
        /// </summary>
        /// <remarks>
        ///   Z values are always zero.
        /// </remarks>
        /// <param name="rectangle">Rectangle to get a point inside</param>
        /// <param name="xMin">Leftmost X value</param>
        /// <param name="yMin">Topmost Y value</param>
        /// <param name="imageWidth">Image width in pixels</param>
        /// <param name="imageHeight">Image width in pixels</param>
        /// <param name="imageRotation">
        ///   Counterclockwise rotation angle of the input image in the image coordinate system.
        ///   In the local coordinate system, this value will often represent a clockwise rotation angle.
        /// </param>
        /// <param name="isMirrored">Set to true if the original coordinates is mirrored</param>
        public static Vector3[] ImageToRectVertices(UnityEngine.Rect rectangle, int xMin, int yMin, int width, int height,
                                                    int imageWidth, int imageHeight, RotationAngle imageRotation = RotationAngle.Rotation0, bool isMirrored = false)
        {
            var p = ImageToPoint(rectangle, xMin, yMin + height, imageWidth, imageHeight, imageRotation, isMirrored);
            var q = ImageToPoint(rectangle, xMin + width, yMin, imageWidth, imageHeight, imageRotation, isMirrored);

            return(GetRectVertices(p, q));
        }
        /// <summary>
        ///   Convert normalized values in the image coordinate system to local coordinate values in Unity.
        ///   If the normalized values are out of [0, 1], the return value will be off the target screen.
        /// </summary>
        /// <param name="normalizedX">Normalized x value in the image coordinate system</param>
        /// <param name="normalizedY">Normalized y value in the image coordinate system</param>
        /// <param name="normalizedZ">Normalized z value in the image coordinate system</param>
        /// <param name="xMin">The minimum X coordinate of the target rectangle</param>
        /// <param name="xMax">The maximum X coordinate of the target rectangle</param>
        /// <param name="yMin">The minimum X coordinate of the target rectangle</param>
        /// <param name="yMax">The maximum X coordinate of the target rectangle</param>
        /// <param name="imageRotation">
        ///   Counterclockwise rotation angle of the input image in the image coordinate system.
        ///   In the local coordinate system, this value will often represent a clockwise rotation angle.
        /// </param>
        /// <param name="isMirrored">Set to true if the original coordinates is mirrored</param>
        public static Vector3 ImageNormalizedToLocalPoint(float normalizedX, float normalizedY, float normalizedZ, float xMin, float xMax, float yMin, float yMax,
                                                          RotationAngle imageRotation = RotationAngle.Rotation0, bool isMirrored = false)
        {
            // Z usually uses roughly the same scale as X
            var zScale = IsInverted(imageRotation) ? (yMax - yMin) : (xMax - xMin);

            return(ImageNormalizedToLocalPoint(normalizedX, normalizedY, normalizedZ, xMin, xMax, yMin, yMax, zScale, imageRotation, isMirrored));
        }
Example #13
0
 /// <summary>
 ///   When the image is rotated back, returns whether the axis parallel to the X axis of the Unity coordinates is pointing in the same direction as the X axis of the Unity coordinates.
 ///   For example, if <paramref name="rotationAngle" /> is <see cref="RotationAngle.Rotation90" /> and <paramRef name="isMirrored" /> is <c>False</c>, this returns <c>True</c>
 ///   because the original X axis will be exactly opposite the Y axis in Unity coordinates if the image is rotated back.
 /// </summary>
 public static bool IsYReversed(RotationAngle rotationAngle, bool isMirrored = false)
 {
     if (isMirrored)
     {
         return(rotationAngle == RotationAngle.Rotation0 || rotationAngle == RotationAngle.Rotation270);
     }
     return(rotationAngle == RotationAngle.Rotation0 || rotationAngle == RotationAngle.Rotation90);
 }
 /// <summary>
 /// 打印二维码
 /// </summary>
 /// <param name="startX">二维码起始x坐标</param>
 /// <param name="startY">二维码起始y坐标</param>
 /// <param name="text">二维码内容</param>
 /// <param name="unitWidth">模块的单位宽度。(1-32)</param>
 /// <param name="level">纠错级别</param>
 /// <param name="rotation">旋转角度</param>
 public IBluetoothPrinterProtocol DrawQrCode(int startX, int startY, string text, QrCodeUnitSize unitWidth,
                                             QrCodeCorrectionLevel level, RotationAngle rotation)
 {
     if (!string.IsNullOrWhiteSpace(text))
     {
         Client.DrawQrCode(startX, startY, text, (int)unitWidth, (int)level, (int)rotation);
     }
     return(this);
 }
Example #15
0
        /// <summary>
        ///   Convert from real world coordinates to Unity local coordinates.
        ///   Assume that the origin is common to the two coordinate systems.
        /// </summary>
        /// <param name="x">X in real world coordinates</param>
        /// <param name="y">Y in real world coordinates</param>
        /// <param name="z">Z in real world coordinates</param>
        /// <param name="scale">Ratio of real world coordinate values to local coordinate values</param>
        /// <param name="imageRotation">
        ///   Counterclockwise rotation angle of the input image in the image coordinate system.
        ///   In the local coordinate system, this value will often represent a clockwise rotation angle.
        /// </param>
        /// <param name="isMirrored">Set to true if the original coordinates is mirrored</param>
        public static Vector3 RealWorldToLocalPoint(float x, float y, float z, Vector3 scale,
                                                    RotationAngle imageRotation = RotationAngle.Rotation0, bool isMirrored = false)
        {
            var(rx, ry) = IsInverted(imageRotation) ? (y, x) : (x, y);
            var realX = IsXReversed(imageRotation, isMirrored) ? -rx : rx;
            var realY = IsYReversed(imageRotation, isMirrored) ? -ry : ry;

            return(Vector3.Scale(new Vector3(realX, realY, z), scale));
        }
Example #16
0
    public static Texture2D RotateImage(Texture2D _source, RotationAngle _angle, bool _flip)
    {
        sourceWidth  = _source.width;
        sourceHeight = _source.height;

        Color32[] sourceColors = _source.GetPixels32();
        Color32[] resultColors = null;

        switch (_angle)
        {
        case RotationAngle.CW0:
            resultWidth  = sourceWidth;
            resultHeight = sourceHeight;
            resultColors = GetColorsCW0(sourceColors, _flip);
            break;

        case RotationAngle.CW90:
            resultWidth  = sourceHeight;
            resultHeight = sourceWidth;
            resultColors = GetColorsCW90(sourceColors, _flip);
            break;

        case RotationAngle.CW180:
            resultWidth  = sourceWidth;
            resultHeight = sourceHeight;
            resultColors = GetColorsCW180(sourceColors, _flip);
            break;

        case RotationAngle.CW270:
            resultWidth  = sourceHeight;
            resultHeight = sourceWidth;
            resultColors = GetColorsCW270(sourceColors, _flip);
            break;
        }

        Texture2D result = new Texture2D(resultWidth, resultHeight, _source.format, false);

        result.filterMode = _source.filterMode;

        result.SetPixels32(resultColors);
        result.Apply();

        return(result);

        /*
         * try
         * {
         *  result[index] = _source[oIndex];
         * }
         * catch (Exception e)
         * {
         *  Debug.Log(xx + "/" + yy + "/" + oIndex + "/" + index);
         *  break;
         * }
         */
    }
 /// <summary>
 /// 打印条码
 /// </summary>
 /// <param name="startX">条码起始x坐标</param>
 /// <param name="startY">条码起始y坐标</param>
 /// <param name="height">条码高度</param>
 /// <param name="lineWidth">条码线条宽度</param>
 /// <param name="text">条码内容</param>
 /// <param name="type">条码类型</param>
 /// <param name="rotation">旋转角度</param>
 public IBluetoothPrinterProtocol DrawBarcode(int startX, int startY, int height, int lineWidth, string text, BarcodeType type,
                                              RotationAngle rotation)
 {
     if (!string.IsNullOrWhiteSpace(text))
     {
         Client.DrawBarcode1D(Helper.ConvertBarcodeType((BarcodeType)type), startX, startY, text, lineWidth,
                              height, (int)rotation, 1);
     }
     return(this);
 }
Example #18
0
        /// <summary>
        /// Читает угол поворота из EXIF
        /// </summary>
        /// <param name="file"></param>
        /// <param name="exifRotationAngle"></param>
        public static void ReadRotationAngleFromEXIF(string file, out RotationAngle exifRotationAngle)
        {
            exifRotationAngle = RotationAngle.Zero;

            using (StreamOnFile newStreamOnFile = new StreamOnFile(file))
            {
                IImageDecoder newIImageDecoder;

                OpenNETCF.Drawing.Imaging.IImagingFactory newImagingFactory = new OpenNETCF.Drawing.Imaging.ImagingFactoryClass();

                int r = newImagingFactory.CreateImageDecoder(newStreamOnFile, DecoderInitFlag.DecoderInitFlagNone, out newIImageDecoder);

                // Ниже используется своя функция обработки EXIF, так как на Philips попытка проверить
                // jpeg из-за некорректных данных рушится в COM. Это случается из-за параметра DecoderInitFlag.DecoderInitFlagNone
                // ImageProperty[] items = ImageUtils.GetAllProperties(newIImageDecoder);
                ImageProperty[] items = GetAllPropertiesInternal(newIImageDecoder);
                if (items.Length == 0)
                {
                    newImagingFactory.CreateImageDecoder(newStreamOnFile, DecoderInitFlag.DecoderInitFlagBuiltIn1st, out newIImageDecoder);
                    items = GetAllPropertiesInternal(newIImageDecoder);
                }

                foreach (ImageProperty item in items)
                {
                    if (item.Id == ImageTag.TAG_ORIENTATION)
                    {
                        try
                        {
                            switch (Convert.ToInt16(item.GetValue()))
                            {
                            case 3:
                                exifRotationAngle = RotationAngle.Clockwise180;
                                break;

                            case 6:
                                exifRotationAngle = RotationAngle.Clockwise90;
                                break;

                            case 8:
                                exifRotationAngle = RotationAngle.Clockwise270;
                                break;

                            default:
                                throw new Exception();
                                break;
                            }
                        }
                        catch (Exception)
                        {
                            exifRotationAngle = RotationAngle.Zero;
                        }
                    }
                }
            }
        }
        /// <summary>
        ///   Convert from image coordinates to local coordinates in Unity.
        /// </summary>
        /// <param name="x">Column value in the image coordinate system</param>
        /// <param name="y">Row value in the image coordinate system</param>
        /// <param name="z">Depth value in the local coordinate system</param>
        /// <param name="screenWidth">
        ///   The target screen width. The returned value will be local to this screen.
        /// </param>
        /// <param name="xMin">The minimum X coordinate of the target rectangle</param>
        /// <param name="xMax">The maximum X coordinate of the target rectangle</param>
        /// <param name="yMin">The minimum X coordinate of the target rectangle</param>
        /// <param name="yMax">The maximum X coordinate of the target rectangle</param>
        /// <param name="imageWidth">Image width in pixels</param>
        /// <param name="imageHeight">Image width in pixels</param>
        /// <param name="imageRotation">
        ///   Counterclockwise rotation angle of the input image in the image coordinate system.
        ///   In the local coordinate system, this value will often represent a clockwise rotation angle.
        /// </param>
        /// <param name="isMirrored">Set to true if the image coordinates is mirrored</param>
        public static Vector3 ImageToLocalPoint(int x, int y, int z, float xMin, float xMax, float yMin, float yMax,
                                                int imageWidth, int imageHeight, RotationAngle imageRotation = RotationAngle.Rotation0, bool isMirrored = false)
        {
            var isInverted = IsInverted(imageRotation);

            var(rectX, rectY)  = isInverted ? (y, x) : (x, y);
            var(width, height) = (xMax - xMin, yMax - yMin);
            var localX = ((IsXReversed(imageRotation, isMirrored) ? imageWidth - rectX : rectX) * width / imageWidth) + xMin;
            var localY = ((IsYReversed(imageRotation, isMirrored) ? imageHeight - rectY : rectY) * height / imageHeight) + yMin;

            return(new Vector3(localX, localY, z));
        }
        /// <summary>
        ///   Convert normalized values in the image coordinate system to local coordinate values in Unity.
        ///   If the normalized values are out of [0, 1], the return value will be off the target screen.
        /// </summary>
        /// <param name="normalizedX">Normalized x value in the image coordinate system</param>
        /// <param name="normalizedY">Normalized y value in the image coordinate system</param>
        /// <param name="normalizedZ">Normalized z value in the image coordinate system</param>
        /// <param name="xMin">The minimum X coordinate of the target rectangle</param>
        /// <param name="xMax">The maximum X coordinate of the target rectangle</param>
        /// <param name="yMin">The minimum X coordinate of the target rectangle</param>
        /// <param name="yMax">The maximum X coordinate of the target rectangle</param>
        /// <param name="zScale">Ratio of Z value in image coordinates to local coordinates in Unity</param>
        /// <param name="imageRotation">
        ///   Counterclockwise rotation angle of the input image in the image coordinate system.
        ///   In the local coordinate system, this value will often represent a clockwise rotation angle.
        /// </param>
        /// <param name="isMirrored">Set to true if the original coordinates is mirrored</param>
        public static Vector3 ImageNormalizedToLocalPoint(float normalizedX, float normalizedY, float normalizedZ, float xMin, float xMax, float yMin, float yMax,
                                                          float zScale, RotationAngle imageRotation = RotationAngle.Rotation0, bool isMirrored = false)
        {
            var isInverted = IsInverted(imageRotation);

            var(nx, ny) = isInverted ? (normalizedY, normalizedX) : (normalizedX, normalizedY);
            var x = IsXReversed(imageRotation, isMirrored) ? Mathf.LerpUnclamped(xMax, xMin, nx) : Mathf.LerpUnclamped(xMin, xMax, nx);
            var y = IsYReversed(imageRotation, isMirrored) ? Mathf.LerpUnclamped(yMax, yMin, ny) : Mathf.LerpUnclamped(yMin, yMax, ny);
            var z = zScale * normalizedZ;

            return(new Vector3(x, y, z));
        }
Example #21
0
        // Deprecated in v 2.3 with no error
        static public Bitmap RotateFlip(Bitmap bitmap, RotateFlipType type)
        {
            if (bitmap == null)
            {
                throw new ArgumentNullException();
            }

            RotationAngle angle = RotationAngle.Zero;
            FlipAxis      axis  = FlipAxis.None;

            switch (type)
            {
            case RotateFlipType.RotateNoneFlipX:
                axis = FlipAxis.X;
                break;

            case RotateFlipType.Rotate90FlipX:
                axis  = FlipAxis.X;
                angle = RotationAngle.Clockwise90;
                break;

            case RotateFlipType.Rotate270FlipX:
                angle = RotationAngle.Clockwise270;
                axis  = FlipAxis.X;
                break;

            case RotateFlipType.RotateNoneFlipXY:
                axis = FlipAxis.X | FlipAxis.Y;
                break;

            case RotateFlipType.Rotate90FlipXY:
                angle = RotationAngle.Clockwise90;
                axis  = FlipAxis.X | FlipAxis.Y;
                break;

            case RotateFlipType.Rotate180FlipXY:
                angle = RotationAngle.Clockwise180;
                axis  = FlipAxis.X | FlipAxis.Y;
                break;

            case RotateFlipType.Rotate270FlipXY:
                angle = RotationAngle.Clockwise270;
                axis  = FlipAxis.X | FlipAxis.Y;
                break;

            case RotateFlipType.RotateNoneFlipY:
                axis = FlipAxis.Y;
                break;
            }

            return(RotateFlip(bitmap, angle, axis));
        }
Example #22
0
        public override void UpdateLayout(Size viewportSize)
        {
            RotationAngle rotationAngle = this.Presenter.Owner.RotationAngle;

            this.pageLayoutInfos.Clear();
            if (this.Document == null)
            {
                this.ContentSize = new Size(0, 0);
                return;
            }

            double height = 0;
            double width  = 0;

            foreach (RadFixedPage page in this.Document.Pages)
            {
                Size pageSize            = this.GetScaledPageSize(page);
                Size rotatedPageSize     = this.RotateSize(pageSize, rotationAngle);
                Size pageSizeWithMargins = new Size(rotatedPageSize.Width + (2 * this.PageMargins.Width), rotatedPageSize.Height + (2 * this.PageMargins.Height));

                if (pageSizeWithMargins.Width > width)
                {
                    width = pageSizeWithMargins.Width;
                }

                double horizontalOffset = ((viewportSize.Width - rotatedPageSize.Width) / 2) - this.PageMargins.Width;
                double verticalOffset   = ((viewportSize.Height - rotatedPageSize.Height) / 2) - this.PageMargins.Height;

                horizontalOffset = Math.Max(0, horizontalOffset);
                verticalOffset   = Math.Max(0, verticalOffset);

                double newHeight = height + pageSizeWithMargins.Height + 2 * verticalOffset;

                Rect positionInView = new Rect(this.PageMargins.Width + horizontalOffset, height + this.PageMargins.Height + verticalOffset, rotatedPageSize.Width, rotatedPageSize.Height);

                TransformGroup transformations = this.CreateTransformations(pageSize, rotationAngle);

                FixedPageLayoutInfo layoutInfo = new FixedPageLayoutInfo(page, positionInView, transformations);

                SinglePageInfo singlePageInfo = new SinglePageInfo(verticalOffset + this.PageMargins.Height, newHeight,
                                                                   rotatedPageSize.Width > viewportSize.Width,
                                                                   rotatedPageSize.Height > viewportSize.Height,
                                                                   layoutInfo.FixedPage, layoutInfo.PositionInView,
                                                                   layoutInfo.Transformations);

                this.pageLayoutInfos.Add(singlePageInfo);

                height = newHeight;
            }

            this.ContentSize = new Size(width, height);
        }
Example #23
0
        /// <summary>
        /// 旋转数组
        /// </summary>
        public static T[,] RotateArray <T>(T[,] array, RotationAngle angle)
        {
            T[,] rotArray = null;

            int width  = array.GetLength(1);
            int height = array.GetLength(0);

            switch (angle)
            {
            case RotationAngle.RotRight90:
            {
                rotArray = new T[width, height];
                for (int i = 0; i < width; i++)
                {
                    for (int j = 0; j < height; j++)
                    {
                        rotArray[i, j] = array[height - 1 - j, i];
                    }
                }
            }
            break;

            case RotationAngle.Rot180:
            {
                rotArray = new T[height, width];
                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        rotArray[i, j] = array[height - 1 - i, width - 1 - j];
                    }
                }
            }
            break;

            case RotationAngle.RotLeft90:
            {
                rotArray = new T[width, height];
                for (int i = 0; i < width; i++)
                {
                    for (int j = 0; j < height; j++)
                    {
                        rotArray[i, j] = array[j, width - 1 - i];
                    }
                }
            }
            break;
            }

            return(rotArray);
        }
        public async Task RotateAsync(RotationAngle angle)
        {
            if (SourceImageFile == null)
            {
                return;
            }

            if (TempImageFile != null)
            {
                await BitmapHelper.RotateAsync(this.TempImageFile, angle);

                OnTempImageFileChanged();
            }
        }
    float RotationAngleToFloat(RotationAngle rotationAngle)
    {
        switch (rotationAngle)
        {
        case RotationAngle.Deg180:
            return(180.0f);

        case RotationAngle.Deg360:
            return(360.0f);

        case RotationAngle.Deg90:
            return(90.0f);
        }
        return(0.0f);
    }
Example #26
0
        public override void WriteGroupCodes()
        {
            WriteGroupCodeValue(10, X0.ToString().Trim());
            WriteGroupCodeValue(20, Y0.ToString().Trim());
            WriteGroupCodeValue(30, Z0.ToString().Trim());

            WriteGroupCodeValue(40, Size.ToString().Trim());

            WriteGroupCodeValue(2, ShapeName.Trim());

            WriteGroupCodeValue(50, RotationAngle.ToString().Trim());
            WriteGroupCodeValue(51, ObliqueAngle.ToString().Trim());

            WriteGroupCodeValue(41, XScale.ToString().Trim());
        }
        /// <summary>
        ///   Convert from camera coordinates to local coordinates in Unity.
        /// </summary>
        /// <param name="x">X in camera coordinates</param>
        /// <param name="y">Y in camera coordinates</param>
        /// <param name="z">Z in camera coordinates</param>
        /// <param name="xMin">The minimum X coordinate of the target rectangle</param>
        /// <param name="xMax">The maximum X coordinate of the target rectangle</param>
        /// <param name="yMin">The minimum X coordinate of the target rectangle</param>
        /// <param name="yMax">The maximum X coordinate of the target rectangle</param>
        /// <param name="focalLengthX">Normalized focal length X in NDC space</param>
        /// <param name="focalLengthY">Normalized focal length Y in NDC space</param>
        /// <param name="principalX">Normalized principal point X in NDC space</param>
        /// <param name="principalY">Normalized principal point Y in NDC space</param>
        /// <param name="zScale">Ratio of Z values in camera coordinates to local coordinates in Unity</param>
        /// <param name="imageRotation">
        ///   Counterclockwise rotation angle of the input image in the image coordinate system.
        ///   In the local coordinate system, this value will often represent a clockwise rotation angle.
        /// </param>
        /// <param name="isMirrored">Set to true if the original coordinates is mirrored</param>
        public static Vector3 CameraToLocalPoint(float x, float y, float z, float xMin, float xMax, float yMin, float yMax,
                                                 float focalLengthX, float focalLengthY, float principalX, float principalY,
                                                 float zScale, RotationAngle imageRotation = RotationAngle.Rotation0, bool isMirrored = false)
        {
            var(ndcX, ndcY)    = ((-focalLengthX * x / z) + principalX, (focalLengthY * y / z) + principalY);
            var(width, height) = (xMax - xMin, yMax - yMin);
            var(nx, ny)        = ((1 + ndcX) / 2.0f, (1 - ndcY) / 2.0f);
            var(rectX, rectY)  = IsInverted(imageRotation) ? (ny * width, nx *height) : (nx * width, ny *height);
            var localX = (IsXReversed(imageRotation, isMirrored) ? width - rectX : rectX) + xMin;
            var localY = (IsYReversed(imageRotation, isMirrored) ? height - rectY : rectY) + yMin;
            // Reverse the sign of Z because camera coordinate system is right-handed
            var localZ = -z * zScale;

            return(new Vector3(localX, localY, localZ));
        }
Example #28
0
        public static PDFNumber RotationAngleToPDFNumber(RotationAngle angle)
        {
            switch (angle)
            {
            case RotationAngle.Rotate180:
                return(new PDFNumber(180));

            case RotationAngle.Rotate270:
                return(new PDFNumber(270));

            case RotationAngle.Rotate90:
                return(new PDFNumber(90));
            }
            return(new PDFNumber(0));
        }
Example #29
0
        /// <summary>
        /// Rotates image by specified amount of degrees
        /// </summary>
        /// <param name="bitmap">Image</param>
        /// <param name="angle">Amount of degrees to rotate image by. Must be 90, 180, or 270</param>
        /// <returns>Rotated image</returns>
        static public Bitmap Rotate(Bitmap bitmap, RotationAngle angle)
        {
            if (bitmap == null)
            {
                throw new ArgumentNullException();
            }

            IBitmapImage imageBitmap = BitmapToIImageBitmap(bitmap);

            try
            {
                return(Rotate(imageBitmap, (float)angle));
            }
            finally
            {
                Marshal.FinalReleaseComObject(imageBitmap);
            }
        }
Example #30
0
 protected void RotateTetrimino()
 {
     if (this.rotation == RotationAngle.Degrees_0)
     {
         this.rotation = RotationAngle.Degrees_90;
     }
     else if (this.rotation == RotationAngle.Degrees_90)
     {
         this.rotation = RotationAngle.Degrees_180;
     }
     else if (this.rotation == RotationAngle.Degrees_180)
     {
         this.rotation = RotationAngle.Degrees_270;
     }
     else if (this.rotation == RotationAngle.Degrees_270)
     {
         this.rotation = RotationAngle.Degrees_0;
     }
 }
Example #31
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         int hashCode = 41;
         if (FileId != null)
         {
             hashCode = hashCode * 59 + FileId.GetHashCode();
         }
         if (PageRange != null)
         {
             hashCode = hashCode * 59 + PageRange.GetHashCode();
         }
         hashCode = hashCode * 59 + RotationAngle.GetHashCode();
         hashCode = hashCode * 59 + FlipHorizontally.GetHashCode();
         hashCode = hashCode * 59 + FlipVertically.GetHashCode();
         return(hashCode);
     }
 }
        public static async Task RotateAsync(StorageFile sourcefile, RotationAngle angle)
        {

            using (IRandomAccessStream sourceStream = await sourcefile.OpenAsync(FileAccessMode.ReadWrite))
            {

                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(sourceStream);

                BitmapEncoder encoder = await BitmapEncoder.CreateForTranscodingAsync(sourceStream, decoder);

                switch (angle)
                {
                    case RotationAngle.None:
                        break;
                    case RotationAngle.Clockwise90Degrees:
                        encoder.BitmapTransform.Rotation = BitmapRotation.Clockwise90Degrees;
                        break;
                    case RotationAngle.Clockwise180Degrees:
                        encoder.BitmapTransform.Rotation = BitmapRotation.Clockwise180Degrees;
                        break;
                    case RotationAngle.Clockwise270Degrees:
                        encoder.BitmapTransform.Rotation = BitmapRotation.Clockwise270Degrees;
                        break;
                    default:
                        break;
                }
                // Flush the data to file.
                await encoder.FlushAsync();

            }
        }
Example #33
0
        /// <summary>
        /// Читает угол поворота из EXIF
        /// </summary>
        /// <param name="file"></param>
        /// <param name="exifRotationAngle"></param>
        public static void ReadRotationAngleFromEXIF(string file, out RotationAngle exifRotationAngle)
        {
            exifRotationAngle = RotationAngle.Zero;

            using (StreamOnFile newStreamOnFile = new StreamOnFile(file))
            {
                IImageDecoder newIImageDecoder;

                OpenNETCF.Drawing.Imaging.IImagingFactory newImagingFactory = new OpenNETCF.Drawing.Imaging.ImagingFactoryClass();

                int r = newImagingFactory.CreateImageDecoder(newStreamOnFile, DecoderInitFlag.DecoderInitFlagNone, out newIImageDecoder);

                // Ниже используется своя функция обработки EXIF, так как на Philips попытка проверить
                // jpeg из-за некорректных данных рушится в COM. Это случается из-за параметра DecoderInitFlag.DecoderInitFlagNone
                // ImageProperty[] items = ImageUtils.GetAllProperties(newIImageDecoder);
                ImageProperty[] items = GetAllPropertiesInternal(newIImageDecoder);
                if (items.Length == 0)
                {
                    newImagingFactory.CreateImageDecoder(newStreamOnFile, DecoderInitFlag.DecoderInitFlagBuiltIn1st, out newIImageDecoder);
                    items = GetAllPropertiesInternal(newIImageDecoder);
                }

                foreach (ImageProperty item in items)
                {
                    if (item.Id == ImageTag.TAG_ORIENTATION)
                    {
                        try
                        {
                            switch (Convert.ToInt16(item.GetValue()))
                            {
                                case 3:
                                    exifRotationAngle = RotationAngle.Clockwise180;
                                    break;

                                case 6:
                                    exifRotationAngle = RotationAngle.Clockwise90;
                                    break;

                                case 8:
                                    exifRotationAngle = RotationAngle.Clockwise270;
                                    break;

                                default:
                                    throw new Exception();
                                    break;
                            }
                        }
                        catch (Exception)
                        {
                            exifRotationAngle = RotationAngle.Zero;
                        }
                    }
                }
            }
        }
Example #34
0
        /// <summary>
        /// Заключительная обработка избражения: вращение на заданный угол
        /// </summary>
        /// <param name="file"></param>
        /// <param name="angle"></param>
        public static void PostProcessImageFile(string file, RotationAngle angle)
        {
            GDI.IImage image;
            GDI.IBitmapImage newIBitmapImage;
            Bitmap newBitmap;
            GDI.ImageInfo newImageInfo;

            if (angle != RotationAngle.Zero)
            {
                ImagingFactory.CreateImageFromFile(file, out image);

                image.GetImageInfo(out newImageInfo);

                ImagingFactory.CreateBitmapFromImage(image, newImageInfo.Width, newImageInfo.Height, PixelFormatID.PixelFormat24bppRGB, DefaultInterpolation, out newIBitmapImage);

                newBitmap = ImageUtils.IBitmapImageToBitmap((IBitmapImage)newIBitmapImage);

                newBitmap = ImageUtils.Rotate(newBitmap, angle);

                Marshal.FinalReleaseComObject(image);

                newBitmap.Save(file, ImageFormat.Jpeg);

                Marshal.FinalReleaseComObject(image);
                Marshal.FinalReleaseComObject(newIBitmapImage);
                newBitmap.Dispose();
            }
        }
Example #35
0
        public async Task RotateAsync(RotationAngle angle)
        {
            if (SourceImageFile == null)
            {
                return;
            }

            if (TempImageFile != null)
            {
                await BitmapHelper.RotateAsync(this.TempImageFile, angle);
                OnTempImageFileChanged();
            }
        }