Пример #1
0
        public void changeSize(IntRect newRect, ResizeType resizeType, IntSize2 bounds)
        {
            bool changesMade = false;

            if ((resizeType & ResizeType.Top) == ResizeType.Top)
            {
                marginTop = newRect.Top;
                if (marginTop < 0)
                {
                    marginTop = 0;
                }
                changesMade = true;
            }

            if ((resizeType & ResizeType.Height) == ResizeType.Height)
            {
                marginBottom = newRect.Height;
                if (marginBottom < 0)
                {
                    marginBottom = 0;
                }
                changesMade = true;
            }

            if (changesMade)
            {
                fireRefreshEditInterface();
            }
        }
Пример #2
0
        public override void changeSizePreview(Element element, IntRect newRect, ResizeType resizeType, IntSize2 bounds)
        {
            appearance.changeSize(element, newRect, resizeType, bounds);
            element.ClearLocalStyles();
            StringBuilder styleString = new StringBuilder();
            StringBuilder classString = new StringBuilder();

            appearance.buildClassList(classString);
            appearance.buildStyleAttribute(styleString);
            if (classString.Length > 0)
            {
                element.SetAttribute("class", classString.ToString());
            }
            else
            {
                element.RemoveAttribute("class");
            }
            if (styleString.Length > 0)
            {
                element.SetAttribute("style", styleString.ToString());
            }
            else
            {
                element.RemoveAttribute("style");
            }
        }
Пример #3
0
        public bool CheckResizing(Point point, out ResizeType resizeType, List <BaseGump> gumps)
        {
            resizeType = ResizeType.None;

            if (gumps == null || gumps.Count != 1)
            {
                return(false);
            }

            if (!gumps[0].Resizable)
            {
                return(false);
            }
            else
            {
                for (int i = 0; i < 4; i++)
                {
                    if (gumps[0].CornerHandles[i].Contains(point))
                    {
                        resizeType = (ResizeType)i + 1;
                        return(true);
                    }
                    if (gumps[0].SideHandles[i].Contains(point))
                    {
                        resizeType = (ResizeType)(i + 5);
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #4
0
        /// <summary>
        /// Clone bitmat with resize.
        /// </summary>
        /// <param name="width">Pixel width.</param>
        /// <param name="height">Pixel height.</param>
        /// <param name="type">Resize algolithm.</param>
        /// <returns>Resized new bitmap.</returns>
        public Bitmap CloneWithResize(int width, int height, ResizeType type = ResizeType.Nearestneighbor)
        {
            var destination = new Bitmap(width, height);

            ResizeProcessor.Process(this, destination, type);
            return(destination);
        }
Пример #5
0
        public static long DetermineQuality(int dimension, ResizeType resizeType)
        {
            if (resizeType == ResizeType.MinDimension)
            {
                if (dimension >= 300)
                {
                    return(90);
                }
                else if (dimension >= 150)
                {
                    return(95);
                }
            }
            else
            {
                if (dimension >= 1200)
                {
                    return(85);
                }
                else if (dimension >= 800)
                {
                    return(90);
                }
                else if (dimension >= 400)
                {
                    return(95);
                }
            }

            return(100);
        }
Пример #6
0
 public void Resize(ResizeType resizeType)
 {
     foreach (var shape in this._shapes.Value)
     {
         shape.Resize(resizeType);
     }
 }
Пример #7
0
        private bool Resizing(int x, int y)
        {
            if (!Resizable)
            {
                return(false);
            }
            else
            {
                for (int i = 0; i < 4; i++)
                {
                    if (CornerHandles[i].Contains(new Point(x, y)))
                    {
                        resizeType = ( ResizeType )i + 1;
                        return(true);
                    }
                    if (SideHandles[i].Contains(new Point(x, y)))
                    {
                        resizeType = ( ResizeType )(i + 5);
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #8
0
 private void ShowAnimationComplete(object sender, object e)
 {
     // Once the animation completes, the app is resized
     shouldResize = ResizeType.ResizeFromShow;
     Container.SetValue(Grid.HeightProperty, viewSize);
     MiddleTranslate.Y = 0;
 }
        private static Size ResizeImage(Size original, Size viewPort, ResizeType type)
        {
            Size result;

            switch (type)
            {
            case ResizeType.DownscaleToViewPort:
                result = DownscaleToViewPort(original, viewPort);
                break;

            case ResizeType.DownscaleToViewPortWidth:
                result = DownscaleToViewPortWidth(original, viewPort);
                break;

            case ResizeType.FitToViewPort:
                result = FitToViewPort(original, viewPort);
                break;

            case ResizeType.FitToViewPortWidth:
                result = FitToViewPortWidth(original, viewPort);
                break;

            default:
                result = original;
                break;
            }

            return(result);
        }
Пример #10
0
        public static void Resize(this Bitmap Image, int Width, int Height, ResizeType Type, ColorSettings Settings)
        {
            Random random = new Random();

            switch (Settings.Color)
            {
            case ColorType.Random:
            {
                Image.Resize(Width, Height, Type,
                             Color.FromArgb(random.Next(255), random.Next(255), random.Next(255)));
                break;
            }

            case ColorType.Range:
            {
                Image.Resize(Width, Height, Type,
                             Color.FromArgb(
                                 random.Next(Settings.SelectedColorRangeRMin,
                                             Settings.SelectedColorRangeRMax),
                                 random.Next(Settings.SelectedColorRangeGMin,
                                             Settings.SelectedColorRangeGMax),
                                 random.Next(Settings.SelectedColorRangeBMin,
                                             Settings.SelectedColorRangeBMax)));
                break;
            }

            case ColorType.Selected:
            {
                Image.Resize(Width, Height, Type, Settings.SelectedColor);
                break;
            }
            }
        }
Пример #11
0
        private void InputPaneHiding(InputPane sender, InputPaneVisibilityEventArgs e)
        {
            if (displacement != 0.0)
            {
                MoveMiddleOnShowing.Stop();

                // Keep in mind that other elements could be shifting out of your control. The sticky app bar, for example
                // will move on its own. You should make sure the input element doesn't get occluded by the bar
                bottomOfList = MiddleScroller.VerticalOffset + MiddleScroller.ActualHeight;

                // If the middle area has actually completed resize, then we want to ignore
                // the default system behavior
                if (resized)
                {
                    // Be careful with this property. Once it has been set, the framework will not change
                    // any layouts in response to the keyboard coming up
                    e.EnsuredFocusedElementInView = true;
                }

                // If the container has already been resized, it should be sized back to the right size
                // Otherwise, there's no need to change the height
                if (Double.IsNaN((double)Container.GetValue(Grid.HeightProperty)))
                {
                    MoveMiddleOnHiding.Begin();
                }
                else
                {
                    shouldResize = ResizeType.ResizeFromHide;
                    Container.ClearValue(Grid.HeightProperty);
                }
            }
        }
 private void ShowAnimationComplete(object sender, object e)
 {
     // Once the animation completes, the app is resized
     shouldResize = ResizeType.ResizeFromShow;
     Container.SetValue(Grid.HeightProperty, viewSize);
     MiddleTranslate.Y = 0;
 }
Пример #13
0
        private void UpdateCursor(ResizeType resizeType)
        {
            switch (resizeType)
            {
            case ResizeType.Left:
                Cursor.Current = Cursors.SizeWE;
                break;

            case ResizeType.Top:
                Cursor.Current = Cursors.SizeNS;
                break;

            case ResizeType.Right:
                Cursor.Current = Cursors.SizeWE;
                break;

            case ResizeType.Bottom:
                Cursor.Current = Cursors.SizeNS;
                break;

            default:
                Cursor.Current = Cursors.Default;
                break;
            }
        }
Пример #14
0
        private void ResizeImagesInFolder(string folderPath, ResizeType resizeType, int width, int height, bool replaceOriginal)
        {
            string[] fileTypes = { ".jpg", ".jpeg", ".png", ".bmp" }; //Add support for gifs??
            foreach (string file in Directory.GetFiles(folderPath))
            {
                if (isCancelled)
                {
                    return;
                }
                bool isValid = false;
                foreach (string filetype in fileTypes)
                {
                    if (file.EndsWith(filetype))
                    {
                        isValid = true;
                        break;
                    }
                }
                if (isValid)
                {
                    ResizeImage(file, resizeType, width, height, replaceOriginal);
                }
            }

            foreach (string folder in Directory.GetDirectories(folderPath))
            {
                ResizeImagesInFolder(folder, resizeType, width, height, replaceOriginal);
            }
        }
Пример #15
0
        public static byte[] ResizeImage(byte[] data, int dimension, ResizeType resizeType, long quality)
        {
            try
            {
                if (dimension == 0)
                {
                    return(data);
                }

                using (MemoryStream ms = new MemoryStream(data))
                {
                    Bitmap bitmap = new Bitmap(ms);

                    var adjustSizeResult = AdjustSizes(bitmap, dimension, resizeType);

                    //if (!adjustSizeResult.Resize)
                    //{
                    //    return data;
                    //}

                    int width  = adjustSizeResult.Width;
                    int height = adjustSizeResult.Height;

                    return(ResizeImageCore(bitmap, width, height, quality));
                }
            }
            catch (Exception ex)
            {
                Nhea.Logging.Logger.Log(ex);
                throw ex;
            }
        }
Пример #16
0
 private static void ResizeShapes(ResizeType resizeType, params IShapeComponent[] shapes)
 {
     foreach (var shape in shapes)
     {
         shape.Resize(resizeType);
     }
 }
Пример #17
0
 public void OnEndDrag(PointerEventData eventData)
 {
     m_dragEnd    = eventData.position;
     m_resizing   = false;
     m_dragging   = false;
     m_resizeType = ResizeType.NONE;
 }
Пример #18
0
        public static void Resize(this Bitmap Image, int Width, int Height, ResizeType Type, Color Color)
        {
            switch (Type)
            {
            case ResizeType.KeepRatio:
            {
                Image.Resize(Width, Height, Color, true);
                break;
            }

            case ResizeType.IgnoreRatio:
            {
                Image.Resize(Width, Height, Color, false);
                break;
            }

            case ResizeType.KeepRatioBackground:
            {
                // Resize
                Image.Resize(Width, Height, Color, true);

                // Background
                Bitmap image = Make(Width, Height, Color);
                image.DrawImage(Image, (Width - Image.Width) / 2, (Height - Image.Height) / 2);
                Image = image;
                break;
            }
            }
        }
Пример #19
0
 private void showResizeHandles(ResizeType handles)
 {
     lastHandles = handles;
     if (allowShowResizeHandles && elementStrategy != null)
     {
         widthAdjust.Visible   = (handles & ResizeType.Width) == ResizeType.Width;
         heightAdjust.Visible  = (handles & ResizeType.Height) == ResizeType.Height;
         bothAdjust.Visible    = (handles & ResizeType.WidthHeight) == ResizeType.WidthHeight;
         xAdjust.Visible       = (handles & ResizeType.Left) == ResizeType.Left;
         yAdjust.Visible       = (handles & ResizeType.Top) == ResizeType.Top;
         xyAdjust.Visible      = (handles & ResizeType.LeftTop) == ResizeType.LeftTop;
         yWidthAdjust.Visible  = (handles & ResizeType.TopWidth) == ResizeType.TopWidth;
         xHeightAdjust.Visible = (handles & ResizeType.LeftHeight) == ResizeType.LeftHeight;
     }
     else
     {
         widthAdjust.Visible   = false;
         heightAdjust.Visible  = false;
         bothAdjust.Visible    = false;
         xAdjust.Visible       = false;
         yAdjust.Visible       = false;
         xyAdjust.Visible      = false;
         yWidthAdjust.Visible  = false;
         xHeightAdjust.Visible = false;
     }
 }
Пример #20
0
 internal SizeChangedEventArgs(UIElement uiElement, double x,
                               double y, ResizeType resizeType)
 {
     _uiElement  = uiElement;
     _x          = x;
     _y          = y;
     _resizeType = resizeType;
 }
Пример #21
0
        public static byte[] Resize(string path, int newWidthPx, int newHeightPx, ResizeType resizeType = ResizeType.Max)
        {
            path = PathHelper.GetFullPath(path);

            byte[] imageBytes = File.ReadAllBytes(path);

            return(Resize(imageBytes, newWidthPx, newHeightPx, resizeType));
        }
Пример #22
0
 protected override void OnMouseUp(MouseEventArgs e)
 {
     if (isSizeable)
     {
         CurrentResizeType = ResizeType.None;
     }
     base.OnMouseUp(e);
 }
Пример #23
0
 protected override void OnMouseDown(MouseEventArgs e)
 {
     if (isSizeable)
     {
         CurrentResizeType = GetResizeType(e.Location);
         SetCursor(CurrentResizeType);
         DragPosition = e.Location;
     }
     base.OnMouseDown(e);
 }
Пример #24
0
        /// <summary>
        /// Calculates picture dimensions whilst maintaining aspect
        /// </summary>
        /// <param name="originalSize">The original picture size</param>
        /// <param name="targetSize">The target picture size (longest side)</param>
        /// <param name="resizeType">Resize type</param>
        /// <param name="ensureSizePositive">A value indicating whether we should ensure that size values are positive</param>
        /// <returns></returns>
        protected virtual Size CalculateDimensions(Size originalSize, int targetSize,
                                                   ResizeType resizeType = ResizeType.LongestSide, bool ensureSizePositive = true)
        {
            float width, height;

            switch (resizeType)
            {
            case ResizeType.LongestSide:
                if (originalSize.Height > originalSize.Width)
                {
                    // portrait
                    width  = originalSize.Width * (targetSize / (float)originalSize.Height);
                    height = targetSize;
                }
                else
                {
                    // landscape or square
                    width  = targetSize;
                    height = originalSize.Height * (targetSize / (float)originalSize.Width);
                }

                break;

            case ResizeType.Width:
                width  = targetSize;
                height = originalSize.Height * (targetSize / (float)originalSize.Width);
                break;

            case ResizeType.Height:
                width  = originalSize.Width * (targetSize / (float)originalSize.Height);
                height = targetSize;
                break;

            default:
                throw new Exception("Not supported ResizeType");
            }

            if (!ensureSizePositive)
            {
                return(new Size((int)Math.Round(width), (int)Math.Round(height)));
            }

            if (width < 1)
            {
                width = 1;
            }

            if (height < 1)
            {
                height = 1;
            }

            //we invoke Math.Round to ensure that no white background is rendered - https://www.nopcommerce.com/boards/t/40616/image-resizing-bug.aspx
            return(new Size((int)Math.Round(width), (int)Math.Round(height)));
        }
Пример #25
0
    public void OnBeginDrag(PointerEventData eventData)
    {
        if (!draggble && !resizable)
        {
            return;
        }

        m_resizing   = false;
        m_dragging   = false;
        m_resizeType = ResizeType.NONE;

        m_dragBegin      = eventData.position;
        m_originPosition = rect.anchoredPosition;
        m_originSize     = rect.sizeDelta;

        if (resizable && (!titleBar || !eventData.selectedObject || eventData.selectedObject != titleBar.gameObject && !eventData.selectedObject.transform.IsChildOf(titleBar)))
        {
            Vector2 pos;
            if (RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, m_dragBegin, UIManager.worldCamera, out pos))
            {
                var re = resizeEdge;
                var hw = rect.sizeDelta.x - re;
                var hh = rect.sizeDelta.y - re;

                if (pos.x < re)
                {
                    m_resizeType |= ResizeType.LEFT;
                }
                if (pos.x > hw)
                {
                    m_resizeType |= ResizeType.RIGHT;
                }
                if (pos.y > -re)
                {
                    m_resizeType |= ResizeType.TOP;
                }
                if (pos.y < -hh)
                {
                    m_resizeType |= ResizeType.BOTTOM;
                }

                m_resizing = m_resizeType != ResizeType.NONE;
                if (m_resizing)
                {
                    return;
                }
            }
        }

        if (draggble && (!titleBar || eventData.selectedObject == titleBar.gameObject))
        {
            m_dragging = true;
        }
    }
Пример #26
0
        public void GetImage(int width, int height, ResizeType widthResizeMethod, ResizeType heightResizeMethod)
        {
            ResizeFrame _rf = GetSize(width, height, widthResizeMethod, heightResizeMethod);

            System.Drawing.Bitmap   final_image = new System.Drawing.Bitmap(_rf.backgroundWidth, _rf.backgroundHeight);
            System.Drawing.Graphics graphic     = System.Drawing.Graphics.FromImage(final_image);
            graphic.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Transparent), new System.Drawing.Rectangle(0, 0, _rf.backgroundWidth, _rf.backgroundHeight));
            graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; /* new way */
            graphic.DrawImage(original_image, _rf.imageX, _rf.imageY, _rf.imageWidth, _rf.imageHeight);
            _final_image = final_image;
        }
Пример #27
0
 public void Resize(ResizeType resize)
 {
     if (resize == ResizeType.Increase)
     {
         this._radius++;
     }
     else
     {
         this._radius--;
     }
 }
Пример #28
0
 public override Cursor ExecuteSelectNode(PointF mousePos, Cursor cursor)
 {
     EnableResize = false;
     if (NodeArry[0].IsContains(PBToImage(mousePos)))
     {
         cursor       = GetCornerCursor(NodeArry[0].Center);
         sizeType     = ResizeType.LeftTop;
         EnableResize = true;
     }
     else if (NodeArry[1].IsContains(PBToImage(mousePos)))
     {
         sizeType     = ResizeType.MidTop;
         cursor       = Cursors.SizeNS;
         EnableResize = true;
     }
     else if (NodeArry[2].IsContains(PBToImage(mousePos)))
     {
         sizeType     = ResizeType.RightTop;
         cursor       = GetCornerCursor(PBToImage(NodeArry[2].Center));
         EnableResize = true;
     }
     else if (NodeArry[3].IsContains(PBToImage(mousePos)))
     {
         sizeType     = ResizeType.LeftMid;
         cursor       = Cursors.SizeWE;
         EnableResize = true;
     }
     else if (NodeArry[4].IsContains(PBToImage(mousePos)))
     {
         sizeType     = ResizeType.RightMid;
         cursor       = Cursors.SizeWE;
         EnableResize = true;
     }
     else if (NodeArry[5].IsContains(PBToImage(mousePos)))
     {
         sizeType     = ResizeType.LeftBottom;
         cursor       = GetCornerCursor(PBToImage(NodeArry[5].Center));
         EnableResize = true;
     }
     else if (NodeArry[6].IsContains(PBToImage(mousePos)))
     {
         sizeType     = ResizeType.MidBottom;
         cursor       = Cursors.SizeNS;
         EnableResize = true;
     }
     else if (NodeArry[7].IsContains(PBToImage(mousePos)))
     {
         sizeType     = ResizeType.RightBottom;
         cursor       = GetCornerCursor(PBToImage(NodeArry[7].Center));
         EnableResize = true;
     }
     return(cursor);
 }
Пример #29
0
 /// <summary>
 /// create single snapshot at the fixed time.
 /// </summary>
 /// <param name="outputPath"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="time"></param>
 /// <param name="type"></param>
 public SnapshotFilter(string outputPath, int width, int height, TimeSpan time, ResizeType type = ResizeType.Scale)
 {
     Name       = "Snapshot";
     FilterType = FilterType.Video;
     OutputPath = outputPath;
     Width      = width;
     Height     = height;
     Time       = time;
     ResizeType = type;
     Number     = null;
     Rank       = 6;
 }
Пример #30
0
        public static AdjustedSizesResult AdjustSizes(Bitmap bitmap, int dimension, ResizeType resizeType)
        {
            AdjustedSizesResult adjustedSizes = new AdjustedSizesResult();

            if (resizeType == ResizeType.MinDimension)
            {
                int relatedDimension = 0;
                adjustedSizes.Resize = true;

                if (bitmap.Height > bitmap.Width)
                {
                    adjustedSizes.Width  = dimension;
                    adjustedSizes.Height = Convert.ToInt32((double)bitmap.Height / ((double)bitmap.Width / (double)dimension));
                    relatedDimension     = bitmap.Width;
                }
                else
                {
                    adjustedSizes.Height = dimension;
                    adjustedSizes.Width  = Convert.ToInt32((double)bitmap.Width / ((double)bitmap.Height / (double)dimension));
                    relatedDimension     = bitmap.Height;
                }

                if (relatedDimension <= dimension)
                {
                    adjustedSizes.Resize = false;
                }
            }
            else
            {
                int relatedDimension = 0;
                adjustedSizes.Resize = true;

                if (bitmap.Height < bitmap.Width)
                {
                    adjustedSizes.Width  = dimension;
                    adjustedSizes.Height = Convert.ToInt32((double)bitmap.Height / ((double)bitmap.Width / (double)dimension));
                    relatedDimension     = bitmap.Width;
                }
                else
                {
                    adjustedSizes.Height = dimension;
                    adjustedSizes.Width  = Convert.ToInt32((double)bitmap.Width / ((double)bitmap.Height / (double)dimension));
                    relatedDimension     = bitmap.Height;
                }

                if (relatedDimension <= dimension)
                {
                    adjustedSizes.Resize = false;
                }
            }

            return(adjustedSizes);
        }
Пример #31
0
 /// <summary>
 /// create single snapshot at the fixed time.
 /// </summary>
 /// <param name="outputPath"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="time"></param>
 /// <param name="type"></param>
 public SnapshotFilter(string outputPath, int width, int height, TimeSpan time, ResizeType type = ResizeType.Scale)
 {
     Name = "Snapshot";
     FilterType = FilterType.Video;
     OutputPath = outputPath;
     Width = width;
     Height = height;
     Time = time;
     ResizeType = type;
     Number = null;
     Rank = 6;
 }
Пример #32
0
        private void ResizeImageToFit(ResizeType rt)
        {
            var app = Globals.ThisAddIn.Application;

            var pres = app.ActivePresentation;
            var wnd  = app.ActiveWindow;
            var view = wnd.View;

            var sel = wnd.Selection;

            if (sel == null)
            {
                MessageBox.Show("Nothing selected; selection null");
                return;
            }

            if (sel.Type == PP.PpSelectionType.ppSelectionNone)
            {
                MessageBox.Show("Nothing selected; selection type null");
                return;
            }

            var pagesetup    = pres.PageSetup;
            var slide_width  = pagesetup.SlideWidth;
            var slide_height = pagesetup.SlideHeight;

            if (sel.Type == PP.PpSelectionType.ppSelectionShapes)
            {
                foreach (PP.Shape shape in sel.ShapeRange)
                {
                    if (shape.Type == MsoShapeType.msoPicture)
                    {
                        if (rt == ResizeType.Width)
                        {
                            shape.Width = slide_width;
                        }
                        else if (rt == ResizeType.Height)
                        {
                            shape.Height = slide_height;
                        }

                        if (this.checkBox_auto_center.Checked)
                        {
                            var picwidth  = shape.Width;
                            var picheight = shape.Height;

                            shape.Left = (slide_width / 2) - (picwidth / 2);
                            shape.Top  = (slide_height / 2) - (picheight / 2);
                        }
                    }
                }
            }
        }
Пример #33
0
        private void InitiateResize(object sender, MouseButtonEventArgs e, ResizeType resizeType)
        {
            var rect = sender as Rectangle;
            if (rect != null)
            {
                _resizeType = resizeType;

                Window win = GetWindow(sender);
                _originalWindowRect = new Rect(win.Left, win.Top, win.Width, win.Height);
                rect.CaptureMouse();
            }

            // 务必设置已处理。否则在调用mainPanel_MouseLeftButtonDown中会处理DragMove
            // Drag会导致之后相应鼠标移动事件时无法获取鼠标位置
            e.Handled = true;
        }
        public ResizeHandlePair(Vector3 point1)
        {
            this.point1 = point1;
            this.point2 = -1 * point1;

            if (point1.sqrMagnitude == 1)
            {
                resizeType = ResizeType.FaceMid;
            }
            else if (point1.sqrMagnitude == 2)
            {
                resizeType = ResizeType.EdgeMid;
            }
            else
            {
                resizeType = ResizeType.Corner;
            }
        }
Пример #35
0
        /// <summary>
        /// Calculates picture dimensions whilst maintaining aspect
        /// </summary>
        /// <param name="originalSize">The original picture size</param>
        /// <param name="targetSize">The target picture size (longest side)</param>
        /// <param name="resizeType">Resize type</param>
        /// <param name="ensureSizePositive">A value indicatingh whether we should ensure that size values are positive</param>
        /// <returns></returns>
        protected virtual Size CalculateDimensions(Size originalSize, int targetSize, 
            ResizeType resizeType = ResizeType.LongestSide, bool ensureSizePositive = true)
        {
            var newSize = new Size();
            switch (resizeType)
            {
                case ResizeType.LongestSide:
                    if (originalSize.Height > originalSize.Width)
                    {
                        // portrait 
                        newSize.Width = (int)(originalSize.Width * (float)(targetSize / (float)originalSize.Height));
                        newSize.Height = targetSize;
                    }
                    else 
                    {
                        // landscape or square
                        newSize.Height = (int)(originalSize.Height * (float)(targetSize / (float)originalSize.Width));
                        newSize.Width = targetSize;
                    }
                    break;
                case ResizeType.Width:
                    newSize.Height = (int)(originalSize.Height * (float)(targetSize / (float)originalSize.Width));
                    newSize.Width = targetSize;
                    break;
                case ResizeType.Height:
                    newSize.Width = (int)(originalSize.Width * (float)(targetSize / (float)originalSize.Height));
                    newSize.Height = targetSize;
                    break;
                default:
                    throw new Exception("Not supported ResizeType");
            }

            if (ensureSizePositive)
            {
                if (newSize.Width < 1)
                    newSize.Width = 1;
                if (newSize.Height < 1)
                    newSize.Height = 1;
            }

            return newSize;
        }
Пример #36
0
 /// <summary>
 /// create multiple snapshot.
 /// </summary>
 /// <param name="outputPath"></param>
 /// <param name="width"></param>
 /// <param name="height"></param>
 /// <param name="number">number of snapshot</param>
 /// <param name="type"></param>
 public SnapshotFilter(string outputPath, int width,int height, int number = 1, ResizeType type = ResizeType.Scale)
 {
     Name = "Snapshot";
     FilterType = FilterType.Video;
     OutputPath = outputPath;
     Width = width;
     Height = height;
     Rank = 6;
     ResizeType = type;
     if (number <= 1)
     {
         Number = null;
         Time = new TimeSpan(0, 0, 0, 1);
     }
     else
     {
         Number = number;
         Time = null;
     }
 }
Пример #37
0
        private ResizeFrame GetSize(int width, int height, ResizeType widthResizeMethod, ResizeType heightResizeMethod)
        {
            decimal original_ratio = (decimal)original_image.Width / original_image.Height;
            decimal target_ratio = (decimal)width / height;

            #region prune
            if (((widthResizeMethod & ResizeType.prune) == ResizeType.prune && (heightResizeMethod & ResizeType.prune) != ResizeType.prune) || ((widthResizeMethod & ResizeType.prune) != ResizeType.prune && (heightResizeMethod & ResizeType.prune) == ResizeType.prune)) throw new Exception("can not only prune one side");
            if ((widthResizeMethod & ResizeType.prune) == ResizeType.prune && (heightResizeMethod & ResizeType.prune) == ResizeType.prune)
                return new ResizeFrame() {
                    backgroundWidth = width, backgroundHeight = height,
                    imageWidth = original_image.Width, imageHeight = original_image.Height,
                    imageX = (width - original_image.Width) / 2, imageY = (height - original_image.Height) / 2
                };
            #endregion

            #region open
            if (((widthResizeMethod & ResizeType.open) == ResizeType.open && (heightResizeMethod & ResizeType.open) != ResizeType.open) || ((widthResizeMethod & ResizeType.open) != ResizeType.open && (heightResizeMethod & ResizeType.open) == ResizeType.open)) throw new Exception("can not only smart one side");
            if ((widthResizeMethod & ResizeType.open) == ResizeType.open && (heightResizeMethod & ResizeType.open) == ResizeType.open) {
                if (target_ratio > original_ratio) {
                    heightResizeMethod = heightResizeMethod | ResizeType.stretch;
                } else {
                    widthResizeMethod = widthResizeMethod | ResizeType.stretch;
                }
            }
            #endregion
            if (((widthResizeMethod & ResizeType.close) == ResizeType.close && (heightResizeMethod & ResizeType.close) != ResizeType.close) || ((widthResizeMethod & ResizeType.close) != ResizeType.close && (heightResizeMethod & ResizeType.close) == ResizeType.close)) throw new Exception("can not only close one side");
            if ((widthResizeMethod & ResizeType.close) == ResizeType.close && (heightResizeMethod & ResizeType.close) == ResizeType.close) {
                if (target_ratio > original_ratio) {
                    widthResizeMethod = widthResizeMethod | ResizeType.stretch;
                } else {
                    heightResizeMethod = heightResizeMethod | ResizeType.stretch;
                }
            }
            if ((widthResizeMethod & ResizeType.stretch) != ResizeType.stretch && (heightResizeMethod & ResizeType.stretch) != ResizeType.stretch) throw new Exception("please set a side resize method to strech at lest.");
            ResizeFrame _rf = new ResizeFrame();
            _rf.backgroundWidth = width;
            _rf.backgroundHeight = height;
            if ((widthResizeMethod & ResizeType.stretch) == ResizeType.stretch) {
                _rf.imageWidth = width;
                if ((heightResizeMethod & ResizeType.stretch) == ResizeType.stretch) {
                    _rf.imageHeight = height;
                    _rf.imageX = _rf.imageY = 0;
                } else {
                    _rf.imageHeight = (int)Math.Ceiling(original_image.Height * (Convert.ToDecimal(width) / original_image.Width));
                    _rf.imageX = 0;
                    _rf.imageY = (height - _rf.imageHeight) / 2;
                    if ((heightResizeMethod & ResizeType.fit) == ResizeType.fit) {
                        _rf.imageY = 0;
                        _rf.backgroundHeight = _rf.imageHeight;
                    }
                }
                return _rf;
            } else if ((heightResizeMethod & ResizeType.stretch) == ResizeType.stretch) {
                _rf.imageHeight = height;
                if ((widthResizeMethod & ResizeType.stretch) == ResizeType.stretch) {
                    _rf.imageWidth = width;
                    _rf.imageX = _rf.imageY = 0;
                } else {
                    _rf.imageWidth = (int)Math.Ceiling(original_image.Width * (Convert.ToDecimal(height) / original_image.Height));
                    _rf.imageX = (width - _rf.imageWidth) / 2;
                    _rf.imageY = 0;
                    if ((widthResizeMethod & ResizeType.fit) == ResizeType.fit) {
                        _rf.imageX = 0;
                        _rf.backgroundWidth = _rf.imageWidth;
                    }
                }
            }
            return _rf;
        }
 private void OnWindowResizeInitiateWE(object sender, System.Windows.Input.MouseEventArgs e)
 {
     isResizing = true;
     resizeType = ResizeType.Width;
 }
Пример #39
0
        /// <summary>
        /// 根据指定:缩略宽、高,缩略图片并保存
        /// 返回图片虚拟路径,和一个警告信息,可根据此信息获取图片合成信息
        /// </summary>
        /// <param name="picpath">原图路径</param>
        /// <param name="model">缩略模式[X,Y,XY](默认XY模式)</param>
        /// <param name="spath">文件保存路径(默认跟路径)</param>
        /// <param name="imgtype">图片保存类型</param>
        /// <param name="mwidth">缩略宽度(默认原图高度)</param>
        /// <param name="mheight">缩略高度(默认原图高度)</param>
        /// <param name="filecache">原文件处理方式</param>
        /// <param name="warning">处理警告信息</param>
        /// <returns>错误,返回错误信息;成功,返回图片路径</returns>
        public static string Resizepic(string picpath, ResizeType model, string spath, ImageType imgtype, double? mwidth, double? mheight, FileCache filecache, out string warning)
        {
            //反馈信息
            System.Text.StringBuilder checkmessage = new System.Text.StringBuilder();

            //文件保存路径
            spath = string.IsNullOrEmpty(spath) ? "/" : spath;

            //缩略宽度
            double swidth = mwidth.HasValue ? double.Parse(mwidth.ToString()) : 0;

            //缩略高度
            double sheight = mheight.HasValue ? double.Parse(mheight.ToString()) : 0;

            //从指定源图片,创建image对象
            string _sourceimg_common_mappath = "";

            //检测源文件
            bool checkfile = false;
            checkfile = FileExistMapPath(picpath, FileCheckModel.C, out _sourceimg_common_mappath);

            System.Drawing.Image _sourceimg_common = null;
            System.Drawing.Bitmap _currimg_common = null;
            System.Drawing.Graphics _g_common = null;

            if (checkfile == true)
            {
                //从源文件创建imgage
                _sourceimg_common = System.Drawing.Image.FromFile(_sourceimg_common_mappath);

                #region 缩略模式
                //缩略模式
                switch (model)
                {
                    case ResizeType.X:

                        #region X模式

                        //根据给定尺寸,获取绘制比例
                        double _width_scale = swidth / _sourceimg_common.Width;
                        //高着比例
                        sheight = _sourceimg_common.Height * _width_scale;

                        #endregion
                        ; break;
                    case ResizeType.Y:
                        #region Y模式

                        //根据给定尺寸,获取绘制比例
                        double _height_scale = sheight / _sourceimg_common.Height;
                        //宽着比例
                        swidth = _sourceimg_common.Width * _height_scale;

                        #endregion
                        ; break;
                    case ResizeType.XY:
                        #region XY模式

                        //当选择XY模式时,mwidth,mheight为必须值
                        if (swidth < 0 || sheight < 0)
                        {
                            checkmessage.Append("error:XY模式,mwidth,mheight为必须值;");
                        }

                        #endregion
                        ; break;
                    default:

                        #region 默认XY模式

                        //当默认XY模式时,mwidth,mheight为必须值
                        if (swidth < 0 || sheight < 0)
                        {
                            checkmessage.Append("error:你当前未选择缩略模式,系统默认XY模式,mwidth,mheight为必须值;");
                        }

                        ; break;
                        #endregion
                }
                #endregion
            }
            else
            {
                checkmessage.Append("error:未能找到缩略原图片," + picpath + ";");
            }

            if (string.IsNullOrEmpty(checkmessage.ToString()))
            {
                //创建bitmap对象
                _currimg_common = new System.Drawing.Bitmap((int)swidth, (int)sheight);

                _g_common = Graphics.FromImage(_currimg_common);

                //设置画笔
                _g_common.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
                _g_common.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                _g_common.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;

                //绘制图片
                _g_common.DrawImage(_sourceimg_common, new Rectangle(0, 0, (int)swidth, (int)sheight), new Rectangle(0, 0, _sourceimg_common.Width, _sourceimg_common.Height), GraphicsUnit.Pixel);

                //保存图片
                string _spath_common_mappath = "";

                //获取图片类型的hashcode值,生成图片后缀名
                int extro = imgtype.GetHashCode();

                string extend = extro == 0 ? ".jpg" : (extro == 1 ? ".gif" : (extro == 2 ? ".png" : ".jpg"));

                //全局文件名
                spath = spath + Guid.NewGuid().ToString() + extend;

                FileExistMapPath(spath, FileCheckModel.M, out _spath_common_mappath);

                switch (imgtype)
                {
                    case ImageType.JPEG: _currimg_common.Save(_spath_common_mappath, System.Drawing.Imaging.ImageFormat.Jpeg); break;
                    case ImageType.GIF: _currimg_common.Save(_spath_common_mappath, System.Drawing.Imaging.ImageFormat.Gif); break;
                    case ImageType.PNG: _currimg_common.Save(_spath_common_mappath, System.Drawing.Imaging.ImageFormat.Png); break;
                }

                //释放
                _sourceimg_common.Dispose();
                _currimg_common.Dispose();
                _g_common.Dispose();

                //处理原文件
                int filecachecode = filecache.GetHashCode();

                //文件缓存方式:Delete,删除原文件
                if (filecachecode == 1)
                {
                    System.IO.File.Delete(_sourceimg_common_mappath);
                }

                //返回相对虚拟路径
                warning = "";
                return spath;
            }

            //释放
            if (_sourceimg_common != null)
            {
                _sourceimg_common.Dispose();
            }
            if (_currimg_common != null)
            {
                _currimg_common.Dispose();
            }
            if (_g_common != null)
            {
                _g_common.Dispose();
            }

            warning = checkmessage.ToString().TrimEnd(';');

            return "";
        }
Пример #40
0
 private void _windowResizeWE_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     _resizeType = ResizeType.Width;
 }
Пример #41
0
 /// <summary>
 /// Hàm Subscribe Event MouseMove, dùng cho chức năng thay đổi kích thước form
 /// </summary>
 void _frm_MouseMove1(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     if (mouseisdown)
     {
         if (RsType != ResizeType.None)
         {// đang resize
             switch (RsType)
             {
                 case ResizeType.Right:
                     {
                         Widthprpt += e.X - MousedownLocation.X;
                         MousedownLocation.X = e.X;
                     }; break;
                 case ResizeType.BottomRight:
                     {
                         int buffWidth = _frm.Width + e.X - MousedownLocation.X;
                         int buffHeight = _frm.Height + e.Y - MousedownLocation.Y;
                         if (buffHeight<Miniumsize.Height)
                         {
                             buffHeight = _frm.Height;
                         }
                         if (buffWidth<Miniumsize.Width)
                         {
                             buffWidth = _frm.Width;
                         }
                         _frm.Size = new System.Drawing.Size(buffWidth, buffHeight);
                         MousedownLocation = e.Location;
                     }; break;
                 case ResizeType.Bottom:
                     {
                         Heighprpt += e.Y - MousedownLocation.Y;
                         MousedownLocation.Y = e.Y;
                     }; break;
             }
         }
     }
     else
     {
         if (_frm.WindowState == FormWindowState.Normal)
         {// Form đang ở trạng thái bình thường - có thể resize được
             if (e.X < Widthprpt - 5)
             {// chuột đang ở giữa
                 if (e.Y > Heighprpt - 5)
                 {// chuột đang ở phía dưới
                     _frm.Cursor = Cursors.SizeNS;
                     RsType = ResizeType.Bottom;
                 }
                 else if (e.Y > this.Height)
                 {// chuột đang ở giữa
                     _frm.Cursor = Cursors.Default;
                     RsType = ResizeType.None;
                 }
             }
             else
             { // chuột đang ở cạnh phải
                 if (e.Y < Heighprpt - 5 && e.Y > this.Height)
                 {// chuột đang ở giữa cạnh phải
                     _frm.Cursor = Cursors.SizeWE;
                     RsType = ResizeType.Right;
                 }
                 else if (e.Y > Heighprpt - 5)
                 { // chuột đang ở góc dưới bên phải
                     _frm.Cursor = Cursors.SizeNWSE;
                     RsType = ResizeType.BottomRight;
                 }
             }
         }
     }
 }
Пример #42
0
        private void window_endResize(object sender, MouseButtonEventArgs e)
        {
            _resizeType = ResizeType.None;

            var rect = sender as Rectangle;
            if (rect != null)
            {
                rect.ReleaseMouseCapture();
            }
            e.Handled = true;
        }
Пример #43
0
        /// <summary>
        /// Uses the TinyPng API to create a resized version of your uploaded image.
        /// </summary>
        /// <param name="result">This is the previous result of running a compression <see cref="Compress(string)"/></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="resizeType"></param>
        /// <returns></returns>
        public async Task<TinyPngResizeResponse> Resize(TinyPngCompressResponse result, int width, int height, ResizeType resizeType = ResizeType.Fit)
        {
            if (result == null)
                throw new ArgumentNullException(nameof(result));
            if (width == 0)
                throw new ArgumentOutOfRangeException(nameof(width));
            if (height == 0)
                throw new ArgumentOutOfRangeException(nameof(height));

            var resizeOp = new ResizeOperation(resizeType, width, height);

            return await Resize(result, resizeOp);
        }
Пример #44
0
        public override void MouseDrag(int x, int y)
        {
            //Resize the new object that was created by right-clicking.
            if (CreateObj && newObj != null)
            {
                Rectangle r = newObj.getRectangle();
                x = Math.Max(0, x / 16);
                y = Math.Max(0, y / 16);
                if (x == lx && y == ly) return;
                lx = x;
                ly = y;
                newObj.X = Math.Min(lx, dx);
                newObj.Y = Math.Min(ly, dy);
                newObj.Width = Math.Abs(lx - dx) + 1;
                newObj.Height = Math.Abs(ly - dy) + 1;
                newObj.UpdateObjCache();
                r = Rectangle.Union(r, newObj.getRectangle());
                Level.repaintTilemap(r.X, r.Y, r.Width, r.Height);
                EdControl.repaint();
                return;
            }

            if(lx == x && ly == y) // don't clone objects if there is no visible movement
                return;

            if(SelectMode)
            {
                findSelectedObjects(x, y, dx, dy, false, true);
                lx = x;
                ly = y;
            }
            else
            {
                UpdateSelectionBounds();
                if (CloneMode)
                {
                    List<LevelItem> newObjects = CloneList(SelectedObjects);
                    EdControl.UndoManager.Do(new AddLvlItemAction(newObjects));

                    CloneMode = false;
                    vertResize = ResizeType.ResizeNone;
                    horResize = ResizeType.ResizeNone;

                    SelectedObjects = newObjects;
                }

                if (horResize == ResizeType.ResizeNone && vertResize == ResizeType.ResizeNone)
                {
                    int xDelta = x-lx;
                    int yDelta = y-ly;
                    if (xDelta < -minBoundX) xDelta = -minBoundX;
                    if (yDelta < -minBoundY) yDelta = -minBoundY;
                    xDelta &= ~(selectionSnap - 1);
                    yDelta &= ~(selectionSnap - 1);
                    if (xDelta == 0 && yDelta == 0) return;
                    minBoundX += xDelta;
                    minBoundY += yDelta;
                    EdControl.UndoManager.Do(new MoveResizeLvlItemAction(SelectedObjects, xDelta, yDelta));
                    lx += xDelta;
                    ly += yDelta;

                    //Force align =D
                    foreach (LevelItem o in SelectedObjects)
                        if (o.rx % selectionSnap != 0 || o.ry % selectionSnap != 0 || o.rwidth % selectionSnap != 0 || o.rheight % selectionSnap != 0)
                            EdControl.UndoManager.Do(new MoveResizeLvlItemAction(UndoManager.ObjToList(o), -o.rx % selectionSnap, -o.ry % selectionSnap, -o.rwidth % selectionSnap, -o.rheight % selectionSnap));

                }
                else
                {
                    int xDelta = x-lx;
                    int yDelta = y-ly;

                    int xMoveDelta = 0;
                    int xResizeDelta = 0;
                    int yMoveDelta = 0;
                    int yResizeDelta = 0;

                    xDelta &= ~(selectionSnap - 1);
                    yDelta &= ~(selectionSnap - 1);
                    if (xDelta == 0 && yDelta == 0) return;

                    if (horResize == ResizeType.ResizeBegin)
                    {
                        if (-xDelta <= -minSizeX + selectionSnap) xDelta = -(-minSizeX + selectionSnap);
                        if (xDelta < -minBoundX) xDelta = -minBoundX;
                        xMoveDelta = xDelta;
                        xResizeDelta = -xDelta;
                    }
                    if (vertResize == ResizeType.ResizeBegin)
                    {
                        if (-yDelta <= -minSizeY + selectionSnap) yDelta = -(-minSizeY + selectionSnap);
                        if (yDelta < -minBoundY) yDelta = -minBoundY;
                        yMoveDelta = yDelta;
                        yResizeDelta = -yDelta;
                    }
                    if (horResize == ResizeType.ResizeEnd)
                    {
                        if (xDelta <= -minSizeX + selectionSnap) xDelta = -minSizeX + selectionSnap;
                        xResizeDelta = xDelta;
                    }
                    if (vertResize == ResizeType.ResizeEnd)
                    {
                        if (yDelta <= -minSizeY + selectionSnap) yDelta = -minSizeY + selectionSnap;
                        yResizeDelta = yDelta;
                    }
                    if (xMoveDelta == 0 && yMoveDelta == 0 && xResizeDelta == 0 && yResizeDelta == 0) return;

                    minBoundX += xMoveDelta;
                    minBoundY += yMoveDelta;
                    minSizeX += xResizeDelta;
                    minSizeY += yResizeDelta;
                    EdControl.UndoManager.Do(new MoveResizeLvlItemAction(SelectedObjects, xMoveDelta, yMoveDelta, xResizeDelta, yResizeDelta));
                    lx += xDelta;
                    ly += yDelta;
                }
            }
        }
Пример #45
0
        public override void MouseDown(int x, int y, MouseButtons buttons)
        {
            //Right clicking creates a new object
            if (buttons == MouseButtons.Right) {
                dx = x / 16;
                dy = y / 16;
                lx = x;
                ly = y;
                CreateObj = true;
                if (tabs.SelectedTab == 2) //The sprite tab
                {
                    NSMBSprite newSprite = new NSMBSprite(Level);
                    newSprite.Type = tabs.sprites.getSelectedType();
                    if (newSprite.Type == -1)
                        return;
                    newSprite.Data = new byte[6];
                    newSprite.x = x;
                    newSprite.y = y;
                    EdControl.UndoManager.Do(new AddLvlItemAction(UndoManager.ObjToList(newSprite)));
                    SelectObject(newSprite);
                    return;
                }
                newObj = new NSMBObject(tabs.objects.getObjectType(), tabs.objects.getTilesetNum(), dx, dy, 1, 1, Level.GFX);
                EdControl.UndoManager.Do(new AddLvlItemAction(UndoManager.ObjToList(newObj)));
                SelectObject(newObj);
                return;
            }
            lx = x;
            ly = y;
            dx = x;
            dy = y;

            bool drag = false;
            getActionAtPos(x, y, out drag, out vertResize, out horResize);
            if (Control.ModifierKeys == Keys.Shift && drag && vertResize == ResizeType.ResizeNone && horResize == ResizeType.ResizeNone)
            {
                vertResize = ResizeType.ResizeEnd;
                horResize = ResizeType.ResizeEnd;
            }
            if (!drag)
            {
                // Select an object
                findSelectedObjects(x, y, x, y, true, true);
                SelectMode = SelectedObjects.Count == 0;
            }
            else if (vertResize == ResizeType.ResizeNone && horResize == ResizeType.ResizeNone)
            {
                List<LevelItem> selectedObjectsBack = new List<LevelItem>();
                selectedObjectsBack.AddRange(SelectedObjects);

                // Select an object
                findSelectedObjects(x, y, x, y, true, true);

                if (SelectedObjects.Count == 0)
                    SelectMode = true;
                else
                {
                    if(selectedObjectsBack.Contains(SelectedObjects[0]))
                        SelectedObjects = selectedObjectsBack;
                }
                UpdateSelectionBounds();
                EdControl.repaint();
            }

            if (!SelectMode)
            {
                CloneMode = Control.ModifierKeys == Keys.Control;
                lx -= selectionSnap / 2;
                ly -= selectionSnap / 2;
            }

            EdControl.repaint();

            tabs.SelectObjects(SelectedObjects);
            UpdatePanel();
        }
Пример #46
0
        /// <summary>
        ///     Applies a resize operation to the input image with the desired size using
        ///     a specified conversion quality and conversion type.
        /// </summary>
        /// <param name="img"> Input image </param>
        /// <param name="size"> Output size </param>
        /// <param name="rType"> Resizing operation </param>
        /// <param name="quality"> Conversion quality </param>
        /// <param name="type"> Conversion type </param>
        public static Bitmap Resize(
            Bitmap img, Size size,
            ResizeType rType = ResizeType.Scaling,
            ConversionQuality quality = ConversionQuality.LowQuality,
            ConversionType type = ConversionType.Copy)
        {
            if (img.Size == size) return img;

            var scaled = new Bitmap(size.Width, size.Height, img.PixelFormat);
            using (var g = Graphics.FromImage(scaled))
            {
                SetConversionQuality(g, quality);
                switch (rType)
                {
                    case ResizeType.Scaling:
                        g.DrawImage(img, new Rectangle(0, 0, size.Width, size.Height));
                        break;
                    case ResizeType.Crop:
                        g.DrawImageUnscaledAndClipped(img,
                            new Rectangle(0, 0, size.Width, size.Height));
                        break;
                }
            }
            SetConversionType(ref img, scaled, type);
            return scaled;
        }
Пример #47
0
 private void button3_Click(object sender, EventArgs e)
 {
     Result = ResizeType.Crop;
     Close();
 }
Пример #48
0
 private void button2_Click(object sender, EventArgs e)
 {
     Result = ResizeType.Scale;
     Close();
 }
Пример #49
0
 public void GetImage(int width, int height, ResizeType widthResizeMethod, ResizeType heightResizeMethod)
 {
     ResizeFrame _rf = GetSize(width, height, widthResizeMethod, heightResizeMethod);
     System.Drawing.Bitmap final_image = new System.Drawing.Bitmap(_rf.backgroundWidth, _rf.backgroundHeight);
     System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(final_image);
     graphic.FillRectangle(new System.Drawing.SolidBrush(System.Drawing.Color.Transparent), new System.Drawing.Rectangle(0, 0, _rf.backgroundWidth, _rf.backgroundHeight));
     graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; /* new way */
     graphic.DrawImage(original_image, _rf.imageX, _rf.imageY, _rf.imageWidth, _rf.imageHeight);
     _final_image = final_image;
 }
Пример #50
0
        private void getActionAtPos(int x, int y, out bool drag, out ResizeType vert, out ResizeType hor)
        {
            drag = false;

            hor = ResizeType.ResizeNone;
            vert = ResizeType.ResizeNone;

            for (int l = SelectedObjects.Count - 1; l > -1; l--)
            {
                LevelItem o = SelectedObjects[l];

                if (o.isResizable && resizeHandles)
                {
                    drag = true;

                    if (x >= o.x - 8 && x <= o.x + 4)
                        hor = ResizeType.ResizeBegin;
                    else if (x >= o.x + o.width - 4 && x <= o.x + o.width + 8)
                        hor = ResizeType.ResizeEnd;
                    else if (x >= o.x && x <= o.x + o.width)
                        hor = ResizeType.ResizeNone;
                    else drag = false;

                    if (y >= o.y - 8 && y <= o.y + 4)
                        vert = ResizeType.ResizeBegin;
                    else if (y >= o.y + o.height - 4 && y <= o.y + o.height + 8)
                        vert = ResizeType.ResizeEnd;
                    else if (y >= o.y && y <= o.y + o.height)
                        vert = ResizeType.ResizeNone;
                    else drag = false;
                    //Only display move cursor on views if cursor is over text
                    if (vert == ResizeType.ResizeNone && hor == ResizeType.ResizeNone && o is NSMBView && !GetViewTextRect(o).Contains(x, y))
                        drag = false;
                }
                else
                {
                    hor = ResizeType.ResizeNone;
                    vert = ResizeType.ResizeNone;

                    drag = false;

                    if (x >= o.x && x < o.x + o.width)
                        if (y >= o.y && y < o.y + o.height)
                            drag = true;
                }

                if (drag) return;
            }
        }
Пример #51
0
        private bool Resizing( int x, int y )
        {
            if( !Resizable )
                return false;
            else
            {
                for( int i = 0; i < 4; i++ )
                {
                    if( CornerHandles[i].Contains( new Point( x, y ) ) )
                    {
                        resizeType = ( ResizeType )i + 1;
                        return true;
                    }
                    if( SideHandles[i].Contains( new Point( x, y ) ) )
                    {
                        resizeType = ( ResizeType )( i + 5 );
                        return true;
                    }
                }
            }

            return false;
        }
Пример #52
0
        public void Resize(int width, int height, ResizeType type = ResizeType.Scale)
        {
            using (var newBitmap = new Bitmap(width, height))
            {
                using (Graphics g = Graphics.FromImage(newBitmap))
                {
                    g.SmoothingMode = SmoothingMode.None;
                    g.InterpolationMode = InterpolationMode.NearestNeighbor;
                    g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    g.Clear(Color.FromArgb(0, 0, 0, 0));

                    using (Image temp = System.Drawing.Image.FromFile(File.FullName))
                    {
                        if (type == ResizeType.Scale)
                            g.DrawImage(temp, 0, 0, newBitmap.Width, newBitmap.Height);
                        else
                            g.DrawImage(temp, 0, 0, temp.Width, temp.Height);
                    }
                }

                newBitmap.Save(File.FullName);

                var md = new Dictionary<string, string>();
                md.Add("Model", Model.Name);
                PNGMetadata.WriteMetadata(File.FullName, md);
            }

            SetImages();

            Undo.Clear();
            Editor.MainForm.CheckUndo();
        }
Пример #53
0
 private void window_initiateResizeNS(object sender, System.Windows.Input.MouseEventArgs e)
 {
     isResizing = true;
     resizeType = ResizeType.Height;
 }
        private void InputPaneHiding(InputPane sender, InputPaneVisibilityEventArgs e)
        {
            if (displacement != 0.0)
            {
                MoveMiddleOnShowing.Stop();

                // Keep in mind that other elements could be shifting out of your control. The sticky app bar, for example
                // will move on its own. You should make sure the input element doesn't get occluded by the bar
                bottomOfList = MiddleScroller.VerticalOffset + MiddleScroller.ActualHeight;

                // If the middle area has actually completed resize, then we want to ignore
                // the default system behavior
                if (resized)
                {
                    // Be careful with this property. Once it has been set, the framework will not change
                    // any layouts in response to the keyboard coming up
                    e.EnsuredFocusedElementInView = true;
                }

                // If the container has already been resized, it should be sized back to the right size
                // Otherwise, there's no need to change the height
                if (Double.IsNaN((double) Container.GetValue(Grid.HeightProperty)))
                {
                    MoveMiddleOnHiding.Begin();
                }
                else
                {
                    shouldResize = ResizeType.ResizeFromHide;
                    Container.ClearValue(Grid.HeightProperty);
                }
            }
        }
Пример #55
0
        public static Image ResizeImage(Image imgToResize, Size size, ResizeType rt = ResizeType.Auto)
        {
            int sourceWidth = imgToResize.Width;
            int sourceHeight = imgToResize.Height;

            int destWidth = size.Width;
            int destHeight = size.Height;

            if (rt != ResizeType.Fixed)
            {
                float nPercent = 0;
                float nPercentW = 0;
                float nPercentH = 0;

                nPercentW = ((float)size.Width / (float)sourceWidth);
                nPercentH = ((float)size.Height / (float)sourceHeight);

                if (rt == ResizeType.Height)
                {
                    nPercent = nPercentH;
                }
                else if (rt == ResizeType.Width)
                {
                    nPercent = nPercentW;
                }
                else
                {
                    if (nPercentH < nPercentW)
                        nPercent = nPercentH;
                    else
                        nPercent = nPercentW;
                }

                if (nPercent > 1.0f)
                    nPercent = 1.0f;

                destWidth = (int)Math.Round(((float)sourceWidth * nPercent));
                destHeight = (int)Math.Round(((float)sourceHeight * nPercent));
            }
            Bitmap b = new Bitmap(destWidth, destHeight);
            Graphics g = Graphics.FromImage((Image)b);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
            g.Dispose();

            return (Image)b;
        }
        private void MiddleScroller_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            // Scrolling should occur after the scrollable element has been resized to ensure
            // that the items the user was looking at remain in view
            if (shouldResize == ResizeType.ResizeFromShow)
            {
                resized = true;
                shouldResize = ResizeType.NoResize;
		MiddleScroller.ChangeView(null, bottomOfList - MiddleScroller.ActualHeight, null, true);
            }
            else if (shouldResize == ResizeType.ResizeFromHide)
            {
                shouldResize = ResizeType.NoResize;
                MiddleTranslate.Y = displacement;
		MiddleScroller.ChangeView(null, bottomOfList - MiddleScroller.ActualHeight, null, true);

                displacement = 0;
                resized = false;

                MoveMiddleOnHiding.Begin();
            }
        }
Пример #57
0
 public ResizeOperation(ResizeType type, int width, int height)
 {
     Method = type;
     Width = width;
     Height = height;
 }
Пример #58
0
 private void _windowResizeNS_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
 {
     _resizeType = ResizeType.Height;
 }