/// <summary> /// Initializes a new instance of the <see cref="ResizeLayer"/> class. /// </summary> /// <param name="size"> /// The <see cref="T:System.Drawing.Size"/> containing the width and height to set the image to. /// </param> /// <param name="resizeMode"> /// The <see cref="ResizeMode"/> to apply to resized image. /// </param> public ResizeLayer(Size size, ResizeMode resizeMode) { this.Size = size; this.ResizeMode = resizeMode; this.AnchorPosition = AnchorPosition.Center; this.BackgroundColor = Color.Transparent; }
protected virtual ResizeMode GetResizeMode(AbsoluteMouseEventArgs e) { if (e.Zoom <= UndreadableZoom) { return(ResizeMode.None); } ResizeMode mode = ResizeMode.None; float squareSize = SelectionMargin / e.Zoom; int horCenter = HorizontalCenter; int verCenter = VerticalCenter; bool left = (e.X >= Left - squareSize && e.X < Left); bool top = (e.Y >= Top - squareSize && e.Y < Top); bool right = (e.X > Right && e.X < Right + squareSize); bool bottom = (e.Y > Bottom && e.Y < Bottom + squareSize); bool center = (e.X >= horCenter - squareSize / 2 && e.X < horCenter + squareSize / 2); bool middle = (e.Y >= verCenter - squareSize / 2 && e.Y < verCenter + squareSize / 2); if (right && (top || middle || bottom)) { mode |= ResizeMode.Right; } if (bottom && (left || center || right)) { mode |= ResizeMode.Bottom; } return(mode); }
private Rectangle CalculateCanvasRectangle(Image source, int targetWidth, int targetHeight, ResizeMode mode) { Rectangle result = new Rectangle(); switch (mode) { case ResizeMode.Crop: case ResizeMode.Letterbox: result.Width = targetWidth; result.Height = targetHeight; break; case ResizeMode.Loose: float sourceAspectRatio = (float)source.Width / (float)source.Height; float targetAspectRatio = (float)targetWidth / (float)targetHeight; if (sourceAspectRatio > targetAspectRatio) { float scaleFactor = ((float)targetWidth / (float)source.Width); result.Width = targetWidth; result.Height = (int)(source.Height * scaleFactor); } else { float scaleFactor = ((float)targetHeight / (float)source.Height); result.Height = targetHeight; result.Width = (int)(source.Width * scaleFactor); } break; } return(result); }
private async Task Resize(string name, string color, ResizeMode mode) { var(mimeType, source) = GetImage("logo.png"); await using (var target = GetStream(name)) { const int w = 1500; const int h = 1500; await sut.CreateThumbnailAsync(source, mimeType, target, new ResizeOptions { Background = color, TargetWidth = w, TargetHeight = h, Mode = mode, }); target.Position = 0; var image = await Image.LoadAsync <Rgba32>(target); Assert.Equal(w, image.Width); Assert.Equal(h, image.Height); var expected = Color.Parse(color ?? "transparent").ToPixel <Rgba32>(); Assert.Equal(expected, image[0, 0]); Assert.Equal(expected, image[0, image.Height - 1]); Assert.Equal(expected, image[image.Width - 1, 0]); Assert.Equal(expected, image[image.Width - 1, image.Height - 1]); } }
protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (ArchiveMaintainer == null || ArchiveMaintainer.LoadingInitialData) { return; } // Do the same thing for everything here for consistency DataTimeRange everything = CurrentArchiveRange; if (MouseDragging == DragMode.New && e.X == MouseDragStart) { LongPoint virtualclicked = LongPoint.DeTranslateFromScreen(new LongPoint(e.Location), everything, DataRange.UnitRange, new LongRectangle(ScrollViewRectangle)); long proposedoffset = ArchiveMaintainer.GraphNow.Ticks - (virtualclicked.X + (GraphWidth.Ticks / 2)); GraphOffset = TimeSpan.FromTicks(proposedoffset > 0 ? proposedoffset : 0); } TimerScroll = ScrollMode.None; Scroller.Stop(); AutoScaleGraph(); GridSpacing = BodgeSpacing(GraphWidth); RefreshXRange(false); MouseDragging = DragMode.None; MouseResizing = ResizeMode.None; }
public virtual Image GetThumbnailImage(Image source, int width, int height, ResizeMode mode, Color paddingColor) { Rectangle canvasSize = CalculateCanvasRectangle(source, width, height, mode); Bitmap canvas = new Bitmap(canvasSize.Width, canvasSize.Height, PixelFormat.Format24bppRgb); Rectangle sourceRectangle = CalculateCropZoomRectangle(source.Width, source.Height, canvas.Width, canvas.Height); using (Graphics graphics = Graphics.FromImage(canvas)) { graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.CompositingQuality = CompositingQuality.HighSpeed; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; using (SolidBrush brush = new SolidBrush(paddingColor)) { graphics.FillRectangle(brush, 0, 0, canvas.Width, canvas.Height); Point upperLeft = new Point(0, 0); Point upperRight = new Point(canvas.Width, 0); Point lowerLeft = new Point(0, canvas.Height); Point[] destinationPoints = new Point[] { upperLeft, upperRight, lowerLeft }; ImageAttributes ia = new ImageAttributes(); ia.SetGamma(1.5f); graphics.DrawImage(source, destinationPoints, sourceRectangle, GraphicsUnit.Pixel, ia); } } return(canvas); }
public static void GoFullscreen(this Window window) { if (window.IsFullscreen()) { return; } _windowState = window.WindowState; _windowStyle = window.WindowStyle; _windowTopMost = window.Topmost; _windowResizeMode = window.ResizeMode; _windowRect.X = window.Left; _windowRect.Y = window.Top; _windowRect.Width = window.Width; _windowRect.Height = window.Height; window.WindowState = WindowState.Normal; window.WindowStyle = WindowStyle.None; window.ResizeMode = ResizeMode.NoResize; window.Topmost = true; var handle = new WindowInteropHelper(window).Handle; Screen screen = Screen.FromHandle(handle); window.MaxWidth = screen.Bounds.Width; window.MaxHeight = screen.Bounds.Height; window.WindowState = WindowState.Maximized; window.Activated += new EventHandler(window_Activated); window.Deactivated += new EventHandler(window_Deactivated); _fullWindow = window; }
/// <summary> /// Returns true if ImageResizeParameters instances are equal /// </summary> /// <param name="input">Instance of ImageResizeParameters to be compared</param> /// <returns>Boolean</returns> public bool Equals(ImageResizeParameters 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)) ) && ( ResizeHorizontal == input.ResizeHorizontal || ResizeHorizontal.Equals(input.ResizeHorizontal) ) && ( ResizeVertical == input.ResizeVertical || ResizeVertical.Equals(input.ResizeVertical) ) && ( ResizeMode == input.ResizeMode || ResizeMode.Equals(input.ResizeMode) ) && ( ResizeUnit == input.ResizeUnit || ResizeUnit.Equals(input.ResizeUnit) )); }
/// <summary> /// Copy the source object. /// </summary> /// <param name="src">Specifies the source data.</param> public override void Copy(OptionalParameter src) { base.Copy(src); if (src is ResizeParameter) { ResizeParameter p = (ResizeParameter)src; m_fProb = p.prob; m_mode = p.resize_mode; m_pad = p.pad_mode; m_rgInterp = new List <InterpMode>(); foreach (InterpMode interp in p.m_rgInterp) { m_rgInterp.Add(interp); } m_nHeight = p.height; m_nWidth = p.width; m_nHeightScale = p.height_scale; m_nWidthScale = p.width_scale; m_rgfPadValue = new List <float>(); foreach (float fPad in p.pad_value) { m_rgfPadValue.Add(fPad); } } }
/// <summary> /// 备份窗口在成为停靠窗口之前的属性。 /// </summary> private void BackupWindowProperties() { _restoreStyle = _window.WindowStyle; _restoreBounds = _window.RestoreBounds; _restoreResizeMode = _window.ResizeMode; _restoreTopmost = _window.Topmost; }
private bool IsMouseOverBorder(Point globalPosition) { //Point coordsInComponentSpace = _component.GlobalToLocal(globalPosition); //_l = InRange(coordsInComponentSpace.X, 0, BorderWeight, true) && InRange(coordsInComponentSpace.Y, 0, _component.Height, true); //_r = InRange(coordsInComponentSpace.X, _component.Width - BorderWeight, _component.Width, true) && InRange(coordsInComponentSpace.Y, 0, _component.Height, true); //_t = InRange(coordsInComponentSpace.Y, 0, BorderWeight, true) && InRange(coordsInComponentSpace.X, 0, _component.Width, true); //_b = InRange(coordsInComponentSpace.Y, _component.Height - BorderWeight, _component.Height, true) && InRange(coordsInComponentSpace.X, 0, _component.Width, true); var leftBorder = _component.LocalToGlobal(new Rectangle(0, 0, BorderWeight, _component.Height)); var rightBorder = _component.LocalToGlobal(new Rectangle(_component.Width - BorderWeight, 0, BorderWeight, _component.Height)); var topBorder = _component.LocalToGlobal(new Rectangle(0, 0, _component.Width, BorderWeight)); var bottomBorder = _component.LocalToGlobal(new Rectangle(0, _component.Height - BorderWeight, _component.Width, BorderWeight)); _l = leftBorder.Contains(globalPosition); _r = rightBorder.Contains(globalPosition); _t = topBorder.Contains(globalPosition); _b = bottomBorder.Contains(globalPosition); bool isResizing = true; if (_l && _t) { _resizeMode = ResizeMode.TopLeft; } else if (_r && _t) { _resizeMode = ResizeMode.TopRight; } else if (_l && _b) { _resizeMode = ResizeMode.BottomLeft; } else if (_r && _b) { _resizeMode = ResizeMode.BottomRight; } else if (_l) { _resizeMode = ResizeMode.Left; } else if (_r) { _resizeMode = ResizeMode.Right; } else if (_t) { _resizeMode = ResizeMode.Top; } else if (_b) { _resizeMode = ResizeMode.Bottom; } else { isResizing = false; } return(isResizing); }
public static void ToFullscreen(this Window window) { if (window.IsFullscreen()) { return; } _windowState = window.WindowState; _windowStyle = window.WindowStyle; _windowTopMost = window.Topmost; _windowResizeMode = window.ResizeMode; _windowRect.X = window.Left; _windowRect.Y = window.Top; _windowRect.Width = window.Width; _windowRect.Height = window.Height; window.WindowState = WindowState.Normal; window.WindowStyle = WindowStyle.None; window.ResizeMode = ResizeMode.NoResize; window.Topmost = true; var handle = new WindowInteropHelper(window).Handle; Screen screen = Screen.FromHandle(handle); window.MaxWidth = screen.Bounds.Width; window.MaxHeight = screen.Bounds.Height; window.WindowState = WindowState.Maximized; window.Activated += new EventHandler(window_Activated); window.Deactivated += new EventHandler(window_Deactivated); _fullWindow = window; }
private static void OnIsFullScreenChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { var window = (Window)sender; var oldFullScreen = (bool)e.OldValue; var fullScreen = (bool)e.NewValue; if (fullScreen != oldFullScreen && window != null) { if (fullScreen) { _windowStyle = window.WindowStyle; _windowState = window.WindowState; _resizeMode = window.ResizeMode; window.WindowState = WindowState.Normal; window.WindowStyle = WindowStyle.None; window.WindowState = WindowState.Maximized; window.ResizeMode = ResizeMode.NoResize; window.Topmost = true; } else { window.Topmost = false; window.WindowStyle = _windowStyle; window.WindowState = _windowState; window.ResizeMode = _resizeMode; } } }
/// <summary>Resizes the bitmap to the specified size.</summary> /// <remarks>This should be overloaded to speed up the resize.</remarks> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="mode">The resize mode.</param> /// <returns></returns> public virtual Bitmap32 Resize(int width, int height, ResizeMode mode = 0) { var result = new Bitmap32(width, height); float w = width; float h = height; if (mode != ResizeMode.None) { float fw = w / (float)Width; float fh = h / (float)Height; float f; if (mode.HasFlag(ResizeMode.TouchFromInside)) { f = Math.Min(fw, fh); } else { f = Math.Max(fw, fh); } w = Width * f; h = Height * f; } float x = (width - w) / 2; float y = (height - h) / 2; result.Draw(this, x, y, w, h); return(result); }
private static Rect windowRect; //记录窗体初始位置 /// <summary> /// 全屏操作 /// </summary> /// <param name="window"></param> public static void FullScreen(this Window window) { if (window.IsFullScreen()) { return; } //记录初始状态 windowState = window.WindowState; windowStyle = window.WindowStyle; windowTopMost = window.Topmost; windowResizeMode = window.ResizeMode; windowRect.X = window.Left; windowRect.Y = window.Top; windowRect.Width = window.Width; windowRect.Height = window.Height; //设置全屏 window.WindowState = WindowState.Maximized; window.WindowStyle = WindowStyle.None; window.ResizeMode = ResizeMode.NoResize;//不允许调整大小 //获取本机显示器分辨率 var handle = new WindowInteropHelper(window).Handle; Screen screen = Screen.FromHandle(handle); window.MaxWidth = screen.Bounds.Width; window.MinHeight = screen.Bounds.Height; //记录对象 fullWindow = window; }
internal void SwitchResizeMode(RTHandle rth, ResizeMode mode) { // Don't do anything is scaling isn't enabled on this RT // TODO: useScaling should probably be moved to ResizeMode.Fixed or something if (!rth.useScaling) { return; } switch (mode) { case ResizeMode.OnDemand: m_AutoSizedRTs.Remove(rth); m_ResizeOnDemandRTs.Add(rth); break; case ResizeMode.Auto: // Resize now so it is consistent with other auto resize RTHs if (m_ResizeOnDemandRTs.Contains(rth)) { DemandResize(rth); } m_ResizeOnDemandRTs.Remove(rth); m_AutoSizedRTs.Add(rth); break; } }
public void ResizeWithOptions() { int width = 50; int height = 100; IResampler sampler = KnownResamplers.Lanczos3; bool compand = true; ResizeMode mode = ResizeMode.Stretch; var resizeOptions = new ResizeOptions { Size = new Size(width, height), Sampler = sampler, Compand = compand, Mode = mode }; this.operations.Resize(resizeOptions); ResizeProcessor resizeProcessor = this.Verify <ResizeProcessor>(); Assert.Equal(width, resizeProcessor.DestinationWidth); Assert.Equal(height, resizeProcessor.DestinationHeight); Assert.Equal(sampler, resizeProcessor.Sampler); Assert.Equal(compand, resizeProcessor.Compand); // Ensure options are not altered. Assert.Equal(width, resizeOptions.Size.Width); Assert.Equal(height, resizeOptions.Size.Height); Assert.Equal(sampler, resizeOptions.Sampler); Assert.Equal(compand, resizeOptions.Compand); Assert.Equal(mode, resizeOptions.Mode); }
private static Rectangle CalculateSourceRectangle(Size imageSize, ResizeMode mode, AnchorStyles anchor, int width, int height) { switch (mode) { case ResizeMode.Percentage: return(new Rectangle(0, 0, imageSize.Width, imageSize.Height)); case ResizeMode.WidthContraint: return(new Rectangle(0, 0, imageSize.Width, imageSize.Height)); case ResizeMode.HeightConstraint: return(new Rectangle(0, 0, imageSize.Width, imageSize.Height)); case ResizeMode.Fixed: return(new Rectangle(0, 0, imageSize.Width, imageSize.Height)); case ResizeMode.Fit: return(new Rectangle(0, 0, imageSize.Width, imageSize.Height)); case ResizeMode.FitNoPadding: return(new Rectangle(0, 0, imageSize.Width, imageSize.Height)); case ResizeMode.Fill: return(CalculateFillRectangle(imageSize, anchor, width, height)); case ResizeMode.Crop: if ((imageSize.Width >= width) && (imageSize.Height >= height)) { return(CalculateCropRectangle(imageSize, anchor, width, height)); } return(new Rectangle(0, 0, imageSize.Width, imageSize.Height)); } return(new Rectangle()); }
public IImage Resize(float width, float height, ResizeMode resizeMode = ResizeMode.Fit, bool disposeOriginal = false) { #if DEBUG Logger.Debug("Resizing not supported in virtual image."); #endif return(this); }
public DispatcherOperation ShowDialog(object content, string title = "", ResizeMode resizeMode = ResizeMode.NoResize, WindowStyle windowStyle = WindowStyle.None, ICommand closeCommand = null) { return(dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { window = new CustomWindow() { SizeToContent = SizeToContent.WidthAndHeight, Title = title, Background = Application.Current.TryFindResource("BackgroundBrush") as Brush, ResizeMode = resizeMode, WindowStyle = windowStyle, Style = Application.Current.TryFindResource("NoResizeWindow") as Style, }; if (closeCommand == null) { window.CloseCommand = new RelayCommand((object o) => window.Close()); } else { window.CloseCommand = closeCommand; } window.ContentRendered += (object sender, EventArgs e) => window.InvalidateVisual(); window.SizeChanged += Win_SizeChanged; window.Content = content; var mainwindow = System.Windows.Application.Current.MainWindow; mainwindow.Opacity = 0.8; window.Owner = Application.Current.MainWindow; var result = window.ShowDialog(); this.OnDialogResultChanged?.Invoke(this, new DialogResultEventArgs(result)); mainwindow.Opacity = 1; }))); }
public static Size Resize(this Size size, int width, int height, ResizeMode mode, float scale) { SizeF sizef = new SizeF(width, height); SizeF newSizef = Resize(sizef, width, height, mode, scale); return(new Size((int)newSizef.Width, (int)newSizef.Height)); }
internal sealed override void MousePressed(AbsoluteMouseEventArgs e) { if (!e.Handled) { bool pressed = Contains(e.Location); if (e.Button == MouseButtons.Left) { pressed |= (IsSelected && GetResizeMode(e) != ResizeMode.None); } if (pressed) { e.Handled = true; var oldResizing = IsResizing; _resizeMode = GetResizeMode(e); if (oldResizing != IsResizing) { _currentOperation = DiagramElementOperation.Resizing; OnBeginUndoableOperation(EventArgs.Empty); } Cursor.Current = _cursor; OnMouseDown(e); } } }
public DefaultBrowserViewModel(ICore core) : this() { string skinName; this.Core = core; this.showInTaskbar = false; skinName = this.Core.GetAttribute("SkinName"); if (skinName != null) { Config.Client.SetAttribute("SkinName", skinName); //this.backColor = this.Core.GetAttribute(skinName + ".BackColor"); //this.foreColor = this.Core.GetAttribute(skinName + ".ForeColor"); } this.resizeMode = System.Windows.ResizeMode.NoResize; this.topmost = true; this.opacity = 0D; this.GetActivationUri(); }
public override object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { try { if (values != null && values.Length == 2) { string buttonName = (string)values[0]; ResizeMode resizeMode = (ResizeMode)values[1]; if (buttonName == CloseButtonName) { return(true); } else if (buttonName == MinimizeButtonName) { return(resizeMode != ResizeMode.NoResize); } else if (buttonName == MaximizeRestoreButtonName) { return(resizeMode != ResizeMode.NoResize && resizeMode != ResizeMode.CanMinimize); } } } catch (Exception) { // use the default return value below } return(true); }
public HttpResponseMessage LogoResizer(int width, int height, ResizeMode resizeMode, string fileName, string moduleName, string sportName) { string fullFilePath = Path.Combine(_rootPath, moduleName, sportName, fileName); //Response.Cache.SetCacheability(HttpCacheability.Public); //Response.Cache.SetLastModified(DateTime.Now); //Response.Cache.SetExpires(DateTime.Now.AddMonths(1)); switch (moduleName) { case "managers": return(Resize(width, height, resizeMode, DefaultPicture.Person, fullFilePath)); case "players": return(Resize(width, height, resizeMode, DefaultPicture.Person, fullFilePath)); case "referees": return(Resize(width, height, resizeMode, DefaultPicture.Person, fullFilePath)); case "stadiums": return(Resize(width, height, resizeMode, DefaultPicture.Stadium, fullFilePath)); default: return(Resize(width, height, resizeMode, DefaultPicture.Blank, fullFilePath)); } }
public Window CreateExternalWindow( bool showInTaskbar = false, bool showActivated = true, bool topmost = true, ResizeMode resizeMode = ResizeMode.NoResize, WindowStyle windowStyle = WindowStyle.None, WindowStartupLocation windowStartupLocation = WindowStartupLocation.CenterScreen, bool showTitleBar = false, bool showMinButton = false, bool showMaxButton = false, bool showCloseButton = false) { return(new CustomWpfWindow.WindowWithDialogs { ShowInTaskbar = showInTaskbar, ShowActivated = showActivated, Topmost = topmost, ResizeMode = resizeMode, WindowStyle = windowStyle, WindowStartupLocation = windowStartupLocation, ShowTitleBar = showTitleBar, ShowMinButton = showMinButton, ShowMaxRestoreButton = showMaxButton, ShowCloseButton = showCloseButton, }); }
public ResizeFilterBuilder To(int width, int height, ResizeMode resizeMode) { Filter.Width = Unit.Pixel(width); Filter.Height = Unit.Pixel(height); Filter.Mode = resizeMode; return(this); }
public void ImageAsync(int id, ResizeMode? type, int? size) { AsyncManager.OutstandingOperations.Increment(); Task.Factory.StartNew(() => { using (var service = new PhotosService()) { var photo = service.GetPhoto(id); if (photo == null) return; // 此処から始まる処理が概ねファイルアクセスで競合エラー起きる // originalとoptimizeへのアクセスがサムネイルとプレビューで同時に発生するから // ファイルアクセスが追いついてないみたい。 // なので、この2ファイルに関してはちょっと早めに処理するか、排他制御出来るように // 制御しましょう。 Stream image; //try { image = service.GetImage(photo, type ?? ResizeMode.Optimize, size ?? 0); } //catch{} AsyncManager.Parameters["image"] = image; AsyncManager.Parameters["contentType"] = photo.ContentType; AsyncManager.OutstandingOperations.Decrement(); } }); }
public ResizeFilterBuilder To(Unit width, Unit height, ResizeMode resizeMode) { Filter.Width = width; Filter.Height = height; Filter.Mode = resizeMode; return(this); }
/// <summary> /// Creates another metro window instance with the given (default) parameters. /// </summary> /// <returns></returns> public Window CreateExternalWindow( bool showInTaskbar = false, bool showActivated = true, bool topmost = true, ResizeMode resizeMode = ResizeMode.NoResize, WindowStyle windowStyle = WindowStyle.None, WindowStartupLocation windowStartupLocation = WindowStartupLocation.CenterScreen, bool showTitleBar = false, bool showTitle = false, bool showMinButton = false, bool showMaxButton = false, bool showCloseButton = false //// bool windowTransitionsEnabled = false ) { return(new MetroWindow { ShowInTaskbar = showInTaskbar, ShowActivated = showActivated, Topmost = topmost, ResizeMode = resizeMode, WindowStyle = windowStyle, WindowStartupLocation = windowStartupLocation, ShowTitleBar = showTitleBar, ShowTitle = showTitle, ShowMinButton = showMinButton, ShowMaxButton = showMaxButton, ShowCloseButton = showCloseButton, //// WindowTransitionsEnabled = windowTransitionsEnabled }); }
public static void GoFullScreen(this Window window) { if (window.IsFullScreen()) { return; } windowState = window.WindowState; windowStyle = window.WindowStyle; windowRect.X = window.Left; windowRect.Y = window.Top; windowRect.Height = window.Height; windowRect.Width = window.Width; windowResizeMode = window.ResizeMode; windowTopMost = window.Topmost; window.WindowState = WindowState.Maximized; window.WindowStyle = WindowStyle.None; window.ResizeMode = ResizeMode.NoResize; var hander = new WindowInteropHelper(window).Handle; Screen screen = Screen.FromHandle(hander); window.MaxWidth = screen.Bounds.Width; window.MaxHeight = screen.Bounds.Height; fullWindow = window; }
public Cursor GetCursor(AbsoluteMouseEventArgs e) { ResizeMode mode = GetResizeMode(e); switch (mode) { case ResizeMode.Bottom: case ResizeMode.Top: return(Cursors.SizeNS); case ResizeMode.Right: case ResizeMode.Left: return(Cursors.SizeWE); case ResizeMode.Bottom | ResizeMode.Right: case ResizeMode.Top | ResizeMode.Left: return(Cursors.SizeNWSE); case ResizeMode.Bottom | ResizeMode.Left: case ResizeMode.Top | ResizeMode.Right: return(Cursors.SizeNESW); default: return(Cursors.Default); } }
public static void GoFullScreen(this Window window) { if (IsFullScreen(window)) { return; } windowState = window.WindowState; windowStyle = window.WindowStyle; windowTopmost = window.Topmost; windowResizeMode = window.ResizeMode; windowRect.X = window.Left; windowRect.Y = window.Top; windowRect.Width = window.Width; windowRect.Height = window.Height; window.WindowState = WindowState.Maximized; window.WindowStyle = WindowStyle.None; windowTopmost = false; windowResizeMode = ResizeMode.NoResize; IntPtr handle = new WindowInteropHelper(window).Handle; Screen screen = Screen.FromHandle(handle); window.Width = screen.Bounds.Width; window.Height = screen.Bounds.Height; fullWindow = window; }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values != null && values.Length == 2 && parameter is string) { bool windowPropValue = System.Convert.ToBoolean(values[0]); ResizeMode windowResizeMode = (ResizeMode)values[1]; string whichButton = System.Convert.ToString(parameter); switch (windowResizeMode) { case ResizeMode.NoResize: return(Visibility.Collapsed); case ResizeMode.CanMinimize: if (whichButton == "MIN") { return(windowPropValue ? Visibility.Visible : Visibility.Collapsed); } return(Visibility.Collapsed); case ResizeMode.CanResize: return(windowPropValue ? Visibility.Visible : Visibility.Collapsed); case ResizeMode.CanResizeWithGrip: return(windowPropValue ? Visibility.Visible : Visibility.Collapsed); default: return(windowPropValue ? Visibility.Visible : Visibility.Collapsed); } } return(Visibility.Visible); }
public XMLControl() { _parentLayout = null; _resizeMode = ResizeMode.Both; _instanceId = _instanceIdCounter; ++_instanceIdCounter; }
public static SizeF Resize(this SizeF size, float width, float height, ResizeMode mode, float scale) { SizeF newSize = new SizeF(width, height); switch (mode) { case ResizeMode.FixedWidthAndHeight: break; case ResizeMode.FixedWidth: newSize.Height = size.Height * width / size.Width; break; case ResizeMode.FixedHeight: newSize.Width = size.Width * height / size.Height; break; case ResizeMode.Crop: if (width > size.Width) newSize.Width = size.Width; if (height > size.Height) newSize.Height = size.Height; break; case ResizeMode.Scale: if (scale < 0) { newSize.Width = -1 * size.Width / scale; newSize.Height = -1 * size.Height / scale; } else if (scale > 0) { newSize.Width = size.Width * scale; newSize.Height = size.Height * scale; } break; case ResizeMode.MaxWidthOrHeight: if (size.Width > width || size.Height > height) { if (size.Width / size.Height > width / height) { newSize.Height = size.Height * width / size.Width; } else { newSize.Width = size.Width * height / size.Height; } } else { newSize.Width = size.Width; newSize.Height = size.Height; } break; default: break; } return newSize; }
/// <summary> /// Initializes a new instance of the <see cref="ResizeLayer"/> class. /// </summary> /// <param name="size"> /// The <see cref="T:System.Drawing.Size"/> containing the width and height to set the image to. /// </param> /// <param name="backgroundColor"> /// The <see cref="T:System.Drawing.Color"/> to set as the background color. /// <remarks>Used for image formats that do not support transparency (Default transparent)</remarks> /// </param> /// <param name="resizeMode"> /// The resize mode to apply to resized image. (Default ResizeMode.Pad) /// </param> /// <param name="anchorPosition"> /// The <see cref="AnchorPosition"/> to apply to resized image. (Default AnchorPosition.Center) /// </param> /// <param name="upscale"> /// Whether to allow up-scaling of images. (Default true) /// </param> public ResizeLayer( Size size, Color? backgroundColor = null, ResizeMode resizeMode = ResizeMode.Pad, AnchorPosition anchorPosition = AnchorPosition.Center, bool upscale = true) { this.Size = size; this.Upscale = upscale; this.BackgroundColor = backgroundColor ?? Color.Transparent; this.ResizeMode = resizeMode; this.AnchorPosition = anchorPosition; }
void handler_MouseLeftDownGlobal(object sender, MouseEventArgGlobal e) { if (!this.ContainsFocus) return; if (this.Cursor == Cursors.SizeWE) this.resizeMode = ResizeMode.H; else if (this.Cursor == Cursors.SizeNS) this.resizeMode = ResizeMode.V; else if (this.Cursor == Cursors.SizeNWSE) this.resizeMode = ResizeMode.B; else this.resizeMode = ResizeMode.N; }
/// <summary> /// Initializes a new instance of the <see cref="ResizeLayer"/> class. /// </summary> /// <param name="size"> /// The <see cref="T:System.Drawing.Size"/> containing the width and height to set the image to. /// </param> /// <param name="resizeMode"> /// The resize mode to apply to resized image. (Default ResizeMode.Pad) /// </param> /// <param name="anchorPosition"> /// The <see cref="AnchorPosition"/> to apply to resized image. (Default AnchorPosition.Center) /// </param> /// <param name="upscale"> /// Whether to allow up-scaling of images. (Default true) /// </param> /// <param name="centerCoordinates"> /// The center coordinates (Default null) /// </param> /// <param name="maxSize"> /// The maximum size to resize an image to. /// Used to restrict resizing based on calculated resizing /// </param> /// <param name="restrictedSizes"> /// The range of sizes to restrict resizing an image to. /// Used to restrict resizing based on calculated resizing /// </param> public ResizeLayer( Size size, ResizeMode resizeMode = ResizeMode.Pad, AnchorPosition anchorPosition = AnchorPosition.Center, bool upscale = true, float[] centerCoordinates = null, Size? maxSize = null, List<Size> restrictedSizes = null) { this.Size = size; this.Upscale = upscale; this.ResizeMode = resizeMode; this.AnchorPosition = anchorPosition; this.CenterCoordinates = centerCoordinates ?? new float[] { }; this.MaxSize = maxSize; this.RestrictedSizes = restrictedSizes ?? new List<Size>(); }
public static string GenerateFileName(string name, ResizeMode type, int size) { var names = new Dictionary<ResizeMode, string> { {ResizeMode.Original, "original{1}"}, {ResizeMode.Optimize, "optimize{1}"}, {ResizeMode.Clip, "clip.{0}{1}"}, {ResizeMode.Fit, "fit.{0}{1}"}, }; var dir = Path.GetDirectoryName(name); var ext = Path.GetExtension(name) ?? ".unknown"; var fileName = string.Format(names[type], size, ext); return string.IsNullOrEmpty(dir) ? fileName : string.Format("{0}/{1}", dir, fileName); }
public static Size Resize(this Size actualSize, Size newSize, ResizeMode resizeMode, OrientationMode orientationMode) { if (orientationMode == OrientationMode.RotateForBestFit) { if ((actualSize.Width > actualSize.Height) && !(newSize.Width > newSize.Height)) newSize = newSize.SwapWidthHeight(); else if ((actualSize.Width < actualSize.Height) && !(newSize.Width < newSize.Height)) newSize = newSize.SwapWidthHeight(); } var heightResizeFactor = newSize.Height / (double)actualSize.Height; var widthResizeFactor = newSize.Width / (double)actualSize.Width; if (resizeMode == ResizeMode.FitsInBox) { if (heightResizeFactor > widthResizeFactor) { newSize = new Size(newSize.Width, (int)((double)actualSize.Height * widthResizeFactor)); } else { newSize = new Size((int)((double)actualSize.Width * heightResizeFactor), newSize.Height); } } else if (resizeMode == ResizeMode.BoxFitsIn || resizeMode == ResizeMode.BoxFitsInCropped) { if (heightResizeFactor < widthResizeFactor) { newSize = new Size(newSize.Width, (int)((double)actualSize.Height * widthResizeFactor)); } else { newSize = new Size((int)((double)actualSize.Width * heightResizeFactor), newSize.Height); } } else if (resizeMode == ResizeMode.Stretch) { // Do nothing } else { throw new ArgumentException("Unsupported ResizeMode value."); } return newSize; }
public static Stream ResizeImage(Stream imageStream, Size size, ResizeMode resizeMode = ResizeMode.Fit, Color? space = null, ImageType? imageType = null) { using (var bitmap = new Bitmap(imageStream)) { if (bitmap.Height == size.Height && bitmap.Width == size.Width) { return imageStream; } using (var processedImage = ResizeImage(bitmap, resizeMode, size, space)) { var format = imageType.HasValue ? ImageExtensionUtility.GetRawFormatByImageFormat(imageType.Value) : bitmap.Height < size.Height || bitmap.Width < size.Width ? ImageFormat.Png : ImageFormat.Jpeg; return ImageFormatUtility.SaveImage(processedImage, format); } } }
/// <summary> /// 进入全屏 /// </summary> /// <param name="window"></param> public static void GoFullscreen(this Window window) { //已经是全屏 if (window.IsFullscreen()) return; //存储窗体信息 _windowState = window.WindowState; _windowStyle = window.WindowStyle; _windowTopMost = window.Topmost; _windowResizeMode = window.ResizeMode; _windowRect.X = window.Left; _windowRect.Y = window.Top; _windowRect.Width = window.Width; _windowRect.Height = window.Height; //变成无边窗体 window.WindowState = WindowState.Normal;//假如已经是Maximized,就不能进入全屏,所以这里先调整状态 window.WindowStyle = WindowStyle.None; window.ResizeMode = ResizeMode.NoResize; window.Topmost = true;//最大化后总是在最上面 //获取窗口句柄 var handle = new WindowInteropHelper(window).Handle; //获取当前显示器屏幕 Screen screen = Screen.FromHandle(handle); //调整窗口最大化,全屏的关键代码就是下面3句 window.MaxWidth = screen.Bounds.Width; window.MaxHeight = screen.Bounds.Height; window.WindowState = WindowState.Maximized; //解决切换应用程序的问题 window.Activated += new EventHandler(window_Activated); window.Deactivated += new EventHandler(window_Deactivated); //记住成功最大化的窗体 _fullWindow = window; }
public WindowDelegate(NavigationWindow window) { _window = window; _dispatcher = window.Dispatcher; _scenes = new List<Scene>(); _resources = new Dictionary<string, ResourceDictionary>(); _sceneIndex = -1; _windowRect = new Rect(); _dispatcher.Invoke(() => { _windowTopmost = window.Topmost; _windowState = window.WindowState; _windowStyle = window.WindowStyle; _windowResizemode = window.ResizeMode; _windowRect.X = window.Left; _windowRect.Y = window.Top; _windowRect.Width = window.Width; _windowRect.Height = window.Height; window.LoadCompleted += (sender, e) => NavigateFinished(); }); }
public static Image ResizeImage(Image originalImage, int width, int height, ResizeMode mode, float scale) { if (width == 0 || height == 0) return originalImage; Size newSize = originalImage.Size.Resize(width, height, mode, scale); float x = 0; float y = 0; float w = originalImage.Width; float h = originalImage.Height; if (mode == ResizeMode.Crop) { x = (originalImage.Width - newSize.Width) / 2; y = (originalImage.Height - newSize.Height) / 2; w = newSize.Width; h = newSize.Height; } //新建一个bmp图片 Image bitmap = new System.Drawing.Bitmap(newSize.Width, newSize.Height); //新建一个画板 Graphics g = System.Drawing.Graphics.FromImage(bitmap); //设置高质量插值法 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; //设置高质量,低速度呈现平滑程度 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //清空画布并以透明背景色填充 g.Clear(Color.Transparent); //在指定位置并且按指定大小绘制原图片的指定部分 g.DrawImage(originalImage, new RectangleF(0, 0, newSize.Width, newSize.Height), new RectangleF(x, y, w, h), GraphicsUnit.Pixel); g.Dispose(); return bitmap; }
/// <summary> /// ����ȫ�� /// </summary> /// <param name="window"></param> public static void GoFullscreen(this Window window) { //�Ѿ���ȫ�� if(window.IsFullscreen()) return; //�洢������Ϣ _windowState = window.WindowState; _windowStyle = window.WindowStyle; _windowTopMost = window.Topmost; _windowResizeMode = window.ResizeMode; _windowRect.X = window.Left; _windowRect.Y = window.Top; _windowRect.Height = window.Width; _windowRect.Height = window.Height; //����ޱߴ��� window.WindowState = WindowState.Normal;//�����Ѿ���Maximized���Ͳ��ܽ���ȫ�������������ȵ���״̬ window.WindowStyle = WindowStyle.None; window.ResizeMode = ResizeMode.NoResize; window.Topmost = true;//��������������� //��ȡ���ھ�� var handle = new WindowInteropHelper(window).Handle; //��ȡ��ǰ��ʾ����Ļ Screen screen = Screen.FromHandle(handle); //�����������,ȫ���Ĺؼ������������3�� window.MaxWidth = screen.Bounds.Width; window.MaxHeight = screen.Bounds.Height; window.WindowState = WindowState.Maximized; //����л�Ӧ�ó�������� window.Activated += new EventHandler(window_Activated); window.Deactivated += new EventHandler(window_Deactivated); //��ס�ɹ���Ĵ��� _fullWindow = window; }
public override void MouseDown(OpenTK.Input.MouseButtonEventArgs e) { base.MouseDown(e); Offset = new Vector2(Utilities.engine.Mouse.X - this.Position.X, Utilities.engine.Mouse.Y - this.Position.Y); this.SendToFront(); Title.SendToFront(); if (this.MouseWithinBottom()) { this.CurrentResizeMode = ResizeMode.Bottom; } if (this.MouseWithinRight()) { this.CurrentResizeMode = ResizeMode.Right; } if (this.MouseWithinLeft()) { this.CurrentResizeMode = ResizeMode.Left; } if (this.MouseWithinRightCorner()) { this.CurrentResizeMode = ResizeMode.BottomRight; } if (this.MouseWithinLeftCorner()) { this.CurrentResizeMode = ResizeMode.BottomLeft; } }
private static bool IsValidResizeMode(ResizeMode value) { return value == ResizeMode.NoResize || value == ResizeMode.CanMinimize || value == ResizeMode.CanResize || value == ResizeMode.CanResizeWithGrip; }
/// <summary> /// Initializes a new instance of the <see cref="ResizeLayer"/> class. /// </summary> /// <param name="backgroundColor"> /// The <see cref="T:System.Drawing.Color"/> to set as the background color. /// <remarks>Used for image formats that do not support transparency</remarks> /// </param> /// <param name="resizeMode"> /// The resize mode to apply to resized image. /// </param> /// <param name="anchorPosition"> /// The <see cref="AnchorPosition"/> to apply to resized image. /// </param> public ResizeLayer(Color backgroundColor, ResizeMode resizeMode = ResizeMode.Pad, AnchorPosition anchorPosition = AnchorPosition.Center) { this.BackgroundColor = backgroundColor; this.ResizeMode = resizeMode; this.AnchorPosition = anchorPosition; }
private void formWindowSize_MouseMove(object sender, MouseEventArgs e) { if (mouseButtonDown) return; if (e.X < MOVE_SIZE && e.Y < MOVE_SIZE) { resizeMode = ResizeMode.TopLeft; } else if (e.X > this.Width - MOVE_SIZE && e.Y < MOVE_SIZE) { resizeMode = ResizeMode.TopRight; } else if (e.X < MOVE_SIZE && e.Y > this.Height - MOVE_SIZE) { resizeMode = ResizeMode.BottomLeft; } else if (e.X > this.Width - MOVE_SIZE && e.Y > this.Height - MOVE_SIZE) { resizeMode = ResizeMode.BottomRight; } else if (e.X < MOVE_SIZE) { resizeMode = ResizeMode.Left; } else if (e.X > this.Width - MOVE_SIZE) { resizeMode = ResizeMode.Right; } else if (e.Y < MOVE_SIZE) { resizeMode = ResizeMode.Top; } else if (e.Y > this.Height - MOVE_SIZE) { resizeMode = ResizeMode.Bottom; } else { resizeMode = ResizeMode.Move; } if (resizeMode == ResizeMode.Top || resizeMode == ResizeMode.Bottom) { this.Cursor = Cursors.SizeNS; } else if (resizeMode == ResizeMode.Left || resizeMode == ResizeMode.Right) { this.Cursor = Cursors.SizeWE; } else if (resizeMode == ResizeMode.TopLeft || resizeMode == ResizeMode.BottomRight) { this.Cursor = Cursors.SizeNWSE; } else if (resizeMode == ResizeMode.TopRight || resizeMode == ResizeMode.BottomLeft) { this.Cursor = Cursors.SizeNESW; } else { this.Cursor = Cursors.SizeAll; } }
/// <summary> /// This method is called when the <see cref="SizeModeChanged"/> event is raised. /// </summary> /// <param name="sender"> The <see cref="GuiItem"/> that raised the event. </param> /// <param name="e"> The new <see cref="ResizeMode"/> for the foreground. </param> protected virtual void OnSizeModeChanged(GuiItem sender, Args e) { sizeMode = e.NewValue; }
private void GenerateResize(string cacheName, string resizeName, ResizeMode type, int size) { var resizer = new ImageResizer(); var resizePath = CacheFullPath(resizeName); if (type != ResizeMode.Original && !File.Exists(resizePath)) { resizer.Resize(cacheName, type, size, resizePath); } }
public static string GenerateFileName(string name, ResizeMode type) { return GenerateFileName(name, type, 0); }
public Stream GetImage(Photo photo, ResizeMode type, int size) { // クラウドに送り込んだ? if (!photo.IsUploaded) return null; // 処理中? //if (!_processing.Lock(photo.Id)) //{ // var dump = string.Format("[id = {0}, type = {1}, size = {2}]", photo.Id, type, size); // Trace.WriteLine(" can't get lock - " + dump + " : " + DateTime.Now); // return null; //} // ファイルがあるなら即返す var loadName = GenerateFileName(photo.FileName, type, size); var loadPath = CacheFullPath(loadName); var entry = new StorageEntry(photo); var resizer = new ImageResizer(); if (!File.Exists(loadPath)) { // キャッシュになければStorageから取り出す。 var cacheName = RetrieveCache(photo.FileName); if (string.IsNullOrEmpty(cacheName)) return null; // 最適化して回転する var optName = GenerateFileName(photo.FileName, ResizeMode.Optimize); var optPath = CacheFullPath(optName); resizer.Optimize(cacheName, optPath); // ローカルキャッシュにリサイズしたものを取得 GenerateResize(optPath, loadName, type, size); } //_processing.Unlock(photo.Id); var bytes = entry.Load(CachePath, loadName); return bytes == null ? null : new MemoryStream(bytes); }
/// <summary> /// Resizes the given image. /// </summary> /// <param name="source">The source <see cref="Image"/> to resize</param> /// <param name="width">The width to resize the image to.</param> /// <param name="height">The height to resize the image to.</param> /// <param name="maxWidth">The default max width to resize the image to.</param> /// <param name="maxHeight">The default max height to resize the image to.</param> /// <param name="restrictedSizes">A <see cref="List{T}"/> containing image resizing restrictions.</param> /// <param name="resizeMode">The mode with which to resize the image.</param> /// <param name="anchorPosition">The anchor position to place the image at.</param> /// <param name="upscale">Whether to allow up-scaling of images. (Default true)</param> /// <param name="centerCoordinates"> /// If the resize mode is crop, you can set a specific center coordinate, use as alternative to anchorPosition /// </param> /// <param name="linear">Whether to resize the image using the linear color space.</param> /// <returns> /// The resized <see cref="Image"/>. /// </returns> private Bitmap ResizeImage( Image source, int width, int height, int maxWidth, int maxHeight, List<Size> restrictedSizes, ResizeMode resizeMode = ResizeMode.Pad, AnchorPosition anchorPosition = AnchorPosition.Center, bool upscale = true, float[] centerCoordinates = null, bool linear = false) { Bitmap newImage = null; try { int sourceWidth = source.Width; int sourceHeight = source.Height; int destinationWidth = width; int destinationHeight = height; maxWidth = maxWidth > 0 ? maxWidth : int.MaxValue; maxHeight = maxHeight > 0 ? maxHeight : int.MaxValue; // Fractional variants for preserving aspect ratio. double percentHeight = Math.Abs(height / (double)sourceHeight); double percentWidth = Math.Abs(width / (double)sourceWidth); int destinationX = 0; int destinationY = 0; // Change the destination rectangle coordinates if box padding. if (resizeMode == ResizeMode.BoxPad) { height = height > 0 ? height : Convert.ToInt32(sourceHeight * percentWidth); width = width > 0 ? width : Convert.ToInt32(sourceWidth * percentHeight); // Only calculate if upscaling. if (sourceWidth < width || sourceHeight < height) { destinationWidth = sourceWidth; destinationHeight = sourceHeight; upscale = true; switch (anchorPosition) { case AnchorPosition.Left: destinationY = (height - sourceHeight) / 2; destinationX = 0; break; case AnchorPosition.Right: destinationY = (height - sourceHeight) / 2; destinationX = width - sourceWidth; break; case AnchorPosition.TopRight: destinationY = 0; destinationX = width - sourceWidth; break; case AnchorPosition.Top: destinationY = 0; destinationX = (width - sourceWidth) / 2; break; case AnchorPosition.TopLeft: destinationY = 0; destinationX = 0; break; case AnchorPosition.BottomRight: destinationY = height - sourceHeight; destinationX = width - sourceWidth; break; case AnchorPosition.Bottom: destinationY = height - sourceHeight; destinationX = (width - sourceWidth) / 2; break; case AnchorPosition.BottomLeft: destinationY = height - sourceHeight; destinationX = 0; break; default: destinationY = (height - sourceHeight) / 2; destinationX = (width - sourceWidth) / 2; break; } } else { // Switch to pad mode to downscale and calculate from there. resizeMode = ResizeMode.Pad; } } // Change the destination rectangle coordinates if padding and // there has been a set width and height. if (resizeMode == ResizeMode.Pad && width > 0 && height > 0) { double ratio; if (percentHeight < percentWidth) { ratio = percentHeight; destinationWidth = Convert.ToInt32(sourceWidth * percentHeight); switch (anchorPosition) { case AnchorPosition.Left: case AnchorPosition.TopLeft: case AnchorPosition.BottomLeft: destinationX = 0; break; case AnchorPosition.Right: case AnchorPosition.TopRight: case AnchorPosition.BottomRight: destinationX = (int)(width - (sourceWidth * ratio)); break; default: destinationX = Convert.ToInt32((width - (sourceWidth * ratio)) / 2); break; } } else { ratio = percentWidth; destinationHeight = Convert.ToInt32(sourceHeight * percentWidth); switch (anchorPosition) { case AnchorPosition.Top: case AnchorPosition.TopLeft: case AnchorPosition.TopRight: destinationY = 0; break; case AnchorPosition.Bottom: case AnchorPosition.BottomLeft: case AnchorPosition.BottomRight: destinationY = (int)(height - (sourceHeight * ratio)); break; default: destinationY = (int)((height - (sourceHeight * ratio)) / 2); break; } } } // Change the destination rectangle coordinates if cropping and // there has been a set width and height. if (resizeMode == ResizeMode.Crop && width > 0 && height > 0) { double ratio; if (percentHeight < percentWidth) { ratio = percentWidth; if (centerCoordinates != null && centerCoordinates.Any()) { double center = -(ratio * sourceHeight) * centerCoordinates[0]; destinationY = (int)center + (height / 2); if (destinationY > 0) { destinationY = 0; } if (destinationY < (int)(height - (sourceHeight * ratio))) { destinationY = (int)(height - (sourceHeight * ratio)); } } else { switch (anchorPosition) { case AnchorPosition.Top: case AnchorPosition.TopLeft: case AnchorPosition.TopRight: destinationY = 0; break; case AnchorPosition.Bottom: case AnchorPosition.BottomLeft: case AnchorPosition.BottomRight: destinationY = (int)(height - (sourceHeight * ratio)); break; default: destinationY = (int)((height - (sourceHeight * ratio)) / 2); break; } } destinationHeight = (int)Math.Ceiling(sourceHeight * percentWidth); } else { ratio = percentHeight; if (centerCoordinates != null && centerCoordinates.Any()) { double center = -(ratio * sourceWidth) * centerCoordinates[1]; destinationX = (int)center + (width / 2); if (destinationX > 0) { destinationX = 0; } if (destinationX < (int)(width - (sourceWidth * ratio))) { destinationX = (int)(width - (sourceWidth * ratio)); } } else { switch (anchorPosition) { case AnchorPosition.Left: case AnchorPosition.TopLeft: case AnchorPosition.BottomLeft: destinationX = 0; break; case AnchorPosition.Right: case AnchorPosition.TopRight: case AnchorPosition.BottomRight: destinationX = (int)(width - (sourceWidth * ratio)); break; default: destinationX = (int)((width - (sourceWidth * ratio)) / 2); break; } } destinationWidth = (int)Math.Ceiling(sourceWidth * percentHeight); } } // Constrain the image to fit the maximum possible height or width. if (resizeMode == ResizeMode.Max) { // If either is 0, we don't need to figure out orientation if (width > 0 && height > 0) { // Integers must be cast to doubles to get needed precision double ratio = (double)height / width; double sourceRatio = (double)sourceHeight / sourceWidth; if (sourceRatio < ratio) { height = 0; } else { width = 0; } } } // Resize the image until the shortest side reaches the set given dimension. if (resizeMode == ResizeMode.Min) { height = height > 0 ? height : Convert.ToInt32(sourceHeight * percentWidth); width = width > 0 ? width : Convert.ToInt32(sourceWidth * percentHeight); double sourceRatio = (double)sourceHeight / sourceWidth; // Ensure we can't upscale. maxHeight = sourceHeight; maxWidth = sourceWidth; upscale = false; // Find the shortest distance to go. int widthDiff = sourceWidth - width; int heightDiff = sourceHeight - height; if (widthDiff < heightDiff) { destinationHeight = Convert.ToInt32(width * sourceRatio); height = destinationHeight; destinationWidth = width; } else if (widthDiff > heightDiff) { destinationHeight = height; destinationWidth = Convert.ToInt32(height / sourceRatio); width = destinationWidth; } else { destinationWidth = width; destinationHeight = height; } } // If height or width is not passed we assume that the standard ratio is to be kept. if (height == 0) { destinationHeight = Convert.ToInt32(sourceHeight * percentWidth); height = destinationHeight; } if (width == 0) { destinationWidth = Convert.ToInt32(sourceWidth * percentHeight); width = destinationWidth; } // Restrict sizes if (restrictedSizes != null && restrictedSizes.Any()) { bool reject = true; foreach (Size restrictedSize in restrictedSizes) { if (restrictedSize.Height == 0 || restrictedSize.Width == 0) { if (restrictedSize.Width == width || restrictedSize.Height == height) { reject = false; } } else if (restrictedSize.Width == width && restrictedSize.Height == height) { reject = false; } } if (reject) { return (Bitmap)source; } } if (width > 0 && height > 0 && width <= maxWidth && height <= maxHeight) { // Exit if upscaling is not allowed. if ((width > sourceWidth || height > sourceHeight) && upscale == false && resizeMode != ResizeMode.Stretch) { return (Bitmap)source; } // Do the resize. Rectangle destination = new Rectangle(destinationX, destinationY, destinationWidth, destinationHeight); //if (this.ImageFormat is GifFormat || (this.ImageFormat is PngFormat && !((PngFormat)this.ImageFormat).IsIndexed)) //{ // newImage = FastResizer.ResizeBilinear((Bitmap)source, width, height, destination, linear); //} //else //{ // if (width <= sourceWidth && height <= sourceHeight) // { // newImage = FastResizer.ResizeBicubicHighQuality((Bitmap)source, width, height, destination, linear); // } // else // { // // Faster // newImage = FastResizer.ResizeBilinear((Bitmap)source, width, height, destination, linear); // } //} newImage = linear ? ResizeLinear(source, width, height, destination) : ResizeComposite(source, width, height, destination); // Reassign the image. source.Dispose(); source = newImage; } } catch (Exception ex) { if (newImage != null) { newImage.Dispose(); } throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex); } return (Bitmap)source; }
/// <summary> /// Inserts or removes data in a tag. /// </summary> /// <param name="stream">The stream to write to.</param> /// <param name="tag">The tag.</param> /// <param name="insertOffset">The offset, from the start of the tag's header, to insert data at.</param> /// <param name="sizeDelta">The size of the data to insert or remove. If positive, data will be inserted. If negative, data will be removed.</param> /// <param name="origin">The type of resize to perform. See <see cref="InsertOrigin"/>.</param> /// <param name="mode">The resize mode. See <see cref="ResizeMode"/>.</param> private void ResizeTag(Stream stream, HaloTag tag, uint insertOffset, int sizeDelta, InsertOrigin origin, ResizeMode mode) { if (sizeDelta == 0) return; var headerSize = GetHeaderSize(tag); if (sizeDelta < 0 && ((origin == InsertOrigin.Before && -sizeDelta > insertOffset) || (origin == InsertOrigin.After && insertOffset + -sizeDelta > headerSize + tag.Size))) throw new ArgumentException("Cannot remove more bytes than there are available in the tag"); // In insertion mode, correct relative offsets to account for inserted data var relativeCompareOffset = (origin == InsertOrigin.Before) ? insertOffset : insertOffset + 1; // hack if (headerSize < relativeCompareOffset) { tag.Size = (uint)(tag.Size + sizeDelta); if (mode == ResizeMode.Insert) { foreach (var fixup in tag.DataFixups.Concat(tag.ResourceFixups)) { if (fixup.WriteOffset + headerSize >= relativeCompareOffset) fixup.WriteOffset = (uint)(fixup.WriteOffset + sizeDelta); if (fixup.TargetOffset + headerSize >= relativeCompareOffset) fixup.TargetOffset = (uint)(fixup.TargetOffset + sizeDelta); } if (tag.MainStructOffset + headerSize >= relativeCompareOffset) tag.MainStructOffset = (uint)(tag.MainStructOffset + sizeDelta); } } // Correct tag offsets var absoluteOffset = _headerOffsets[tag.Index] + insertOffset; var absoluteCompareOffset = (origin == InsertOrigin.Before) ? absoluteOffset : absoluteOffset + 1; // hack for (var i = 0; i < _tags.Count; i++) { if (_tags[i] == null) continue; if (_headerOffsets[i] >= absoluteCompareOffset) // Header offset (absolute) _headerOffsets[i] = (uint)(_headerOffsets[i] + sizeDelta); if (_tags[i].Offset >= absoluteCompareOffset) // Data offset (absolute) _tags[i].Offset = (uint)(_tags[i].Offset + sizeDelta); } // Insert/remove the data if (sizeDelta < 0 && origin == InsertOrigin.Before) absoluteOffset = (uint)(absoluteOffset + sizeDelta); stream.Position = absoluteOffset; if (sizeDelta > 0) StreamUtil.Insert(stream, sizeDelta, 0); else StreamUtil.Remove(stream, -sizeDelta); }
public override void MouseUp(OpenTK.Input.MouseButtonEventArgs e) { if (CurrentResizeMode != ResizeMode.None) { ResizeThink(); this.CurrentResizeMode = ResizeMode.None; Title.SetWidth(this.Width); } Offset = Vector2.Zero; }
private void _init_rest() { lbl_title.Content = lbl_title.Content as string + " v" + GetRunningVersion(); _is_expanded = main_context_view_expanded.IsChecked; _is_fullscreen = false; _player_state = PLAYER_STATE.NOT_LOADED; _progress_state = DURATION_LABEL.ELAPSED; _current_media_type = MEDIA_TYPE.VIDEO; _ml_main_background = border_media_element.Background; _resize_mode_default = this.ResizeMode; _temp_position = TimeSpan.MinValue; _playlist_history = new Stack<MyMediaFile>(100); _timer = new DispatcherTimer(); _timer.Interval = new TimeSpan(0, 0, 1); _timer.Tick += new EventHandler((sender, e) => { if (!_is_slider_dragging && _player_state == PLAYER_STATE.PLAYING) { sl_progress.Value = ml_main.Position.TotalSeconds; this.TaskbarItemInfo.ProgressValue = ml_main.NaturalDuration.HasTimeSpan ? sl_progress.Value / ml_main.NaturalDuration.TimeSpan.TotalSeconds : 0; } }); _timer.Start(); _components_visible_timer = new DispatcherTimer(); _components_visible_timer.Interval = new TimeSpan(0, 0, CONSTANT_HIDE_COMPONENTS_DELAY); _components_visible_timer.Tick += new EventHandler((sender, e) => { if (_is_expanded || _is_fullscreen && _player_state == PLAYER_STATE.PLAYING && !main_context.IsOpen) { _components_state(Visibility.Hidden); } }); _components_visible_timer.Start(); _timer_dragmove = new DispatcherTimer(); _timer_dragmove.Interval = new TimeSpan(0, 0, 0, 0, DRAGMOVE_TIME_MS); _timer_dragmove.Tick += new EventHandler((t_sender, t_e) => { if (Mouse.LeftButton == MouseButtonState.Pressed) { DragMove(); } _timer_dragmove.Stop(); }); /* Subscribe to custome eventhandler for external application launch */ App.ExternelApplicationLauncy += mainwindow_root_loaded; }
private void SetFullScreen() { _windowState = _window.WindowState; _windowStyle = _window.WindowStyle; _windowResizemode = _window.ResizeMode; _windowRect.X = _window.Left; _windowRect.Y = _window.Top; _windowRect.Width = _window.Width; _windowRect.Height = _window.Height; _window.WindowState = WindowState.Normal; _window.WindowStyle = WindowStyle.None; _window.ResizeMode = ResizeMode.NoResize; _window.Topmost = true; _window.Left = 0; _window.Top = 0; _window.Width = SystemParameters.PrimaryScreenWidth; _window.Height = SystemParameters.PrimaryScreenHeight; _window.Activated += Window_Active; _window.Deactivated += Window_Deactive; }
/// <summary> /// Handles the CheckedChanged event of the checkBoxResizeQuestion control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev05, 2007-11-29</remarks> private void checkBoxResizeQuestion_CheckedChanged(object sender, EventArgs e) { if (changingCheckstate) return; if (!checkBoxResizeQuestion.Checked) { QuestionResizeMode = ResizeMode.None; checkBoxResizeQuestion.Image = Resources.resize; } else { TaskDialogResult result = ShowResizeDialog(); int commandButtonResult = result.CommandButtonsIndex; switch (commandButtonResult) { case 0: QuestionResizeMode = ResizeMode.Small; checkBoxResizeQuestion.Image = Resources.resizeS; Modified = true; break; case 1: QuestionResizeMode = ResizeMode.Medium; checkBoxResizeQuestion.Image = Resources.resizeM; Modified = true; break; case 2: QuestionResizeMode = ResizeMode.Large; checkBoxResizeQuestion.Image = Resources.resizeL; Modified = true; break; case 3: default: QuestionResizeMode = ResizeMode.None; checkBoxResizeQuestion.Image = Resources.resize; break; } if (result.VerificationChecked) { AnswerResizeMode = QuestionResizeMode; checkBoxResizeAnswer.Image = checkBoxResizeQuestion.Image; } } checkBoxResizeQuestion.Checked = (QuestionResizeMode != ResizeMode.None); }