public void ImageBoundsFromContentAlignmentMiddleRightTest() { Rectangle imageBounds = NuGenControlPaint.ImageBoundsFromContentAlignment(_imageSize, _fitRectangle, ContentAlignment.MiddleRight); Assert.AreEqual(_rectWidth - _imageSize.Width, imageBounds.Left); Assert.AreEqual(_rectHeight / 2 - _imageSize.Height / 2, imageBounds.Top); }
public void ImageBoundsFromContentAlignmentTopLeftTest() { Rectangle imageBounds = NuGenControlPaint.ImageBoundsFromContentAlignment(_imageSize, _fitRectangle, ContentAlignment.TopLeft); Assert.AreEqual(0, imageBounds.Left); Assert.AreEqual(0, imageBounds.Top); }
public void ImageBoundsFromContentAlignmentBottomLeftTest() { Rectangle imageBounds = NuGenControlPaint.ImageBoundsFromContentAlignment(_imageSize, _fitRectangle, ContentAlignment.BottomLeft); Assert.AreEqual(0, imageBounds.Left); Assert.AreEqual(_rectHeight - _imageSize.Height, imageBounds.Top); }
public void ImageBoundsFromContentAlignmentBottomCenterTest() { Rectangle imageBounds = NuGenControlPaint.ImageBoundsFromContentAlignment(_imageSize, _fitRectangle, ContentAlignment.BottomCenter); Assert.AreEqual(_rectWidth / 2 - 8, imageBounds.Left); Assert.AreEqual(_rectHeight - 16, imageBounds.Top); Assert.AreEqual(_imageSize.Width, imageBounds.Width); Assert.AreEqual(_imageSize.Height, imageBounds.Height); }
/// <summary> /// </summary> /// <param name="imageBoundsParams"></param> /// <returns></returns> public Rectangle GetImageBounds(NuGenImageBoundsParams imageBoundsParams) { Image image = imageBoundsParams.Image; if (image != null) { return(NuGenControlPaint.ImageBoundsFromContentAlignment( imageBoundsParams.Image.Size, imageBoundsParams.Bounds, imageBoundsParams.ImageAlign )); } return(Rectangle.Empty); }
public void ExportWithWatermark( Image image , NuGenImageType imageType , NuGenImageFileFormat fileFormat , Size resolution , int watermarkCount , Font watermarkFont , Color watermarkColor , ContentAlignment watermarkAlignment , string path , string filename ) { if (image == null) { throw new ArgumentNullException("image"); } if (watermarkFont == null) { throw new ArgumentNullException("watermarkFont"); } if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } if (string.IsNullOrEmpty(filename)) { throw new ArgumentNullException("filename"); } using (Graphics g = Graphics.FromImage(image)) using (SolidBrush sb = new SolidBrush(watermarkColor)) { string text = watermarkCount.ToString(CultureInfo.CurrentCulture); Size watermarkSize = g.MeasureString(text, watermarkFont).ToSize(); Rectangle watermarkBounds = NuGenControlPaint.ImageBoundsFromContentAlignment( watermarkSize , new Rectangle(new Point(0, 0), image.Size) , watermarkAlignment ); g.DrawString(text, watermarkFont, sb, watermarkBounds); } this.Export(image, imageType, fileFormat, resolution, path, filename); }
protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; Rectangle bounds = this.ClientRectangle; bool stretch = Settings.Default.StretchSlide; if (_currentSlide != null) { if (stretch) { g.DrawImage(_currentSlide, bounds); } else { bool random = Settings.Default.RandomSlideAlignment; Size initialImageSize; if (Settings.Default.SlideFitScreen) { initialImageSize = NuGenControlPaint.ScaleToFit(this.ClientRectangle, _currentSlide.Size).Size; } else { initialImageSize = _currentSlide.Size; } ContentAlignment align; if (random) { align = (ContentAlignment)_random.Next(0, 8); } else { align = Settings.Default.SlideAlignment; } Rectangle imageBounds = NuGenControlPaint.ImageBoundsFromContentAlignment( initialImageSize, bounds, align ); g.DrawImage(_currentSlide, imageBounds); } } }
/// <summary> /// </summary> /// <param name="imageBoundsParams"></param> /// <returns></returns> public Rectangle GetImageBounds(NuGenBoundsParams imageBoundsParams) { if (imageBoundsParams == null) { throw new ArgumentNullException("imageBoundsParams"); } imageBoundsParams.ImageAlign = NuGenControlPaint.RTLContentAlignment( imageBoundsParams.ImageAlign , imageBoundsParams.RightToLeft ); return(NuGenControlPaint.ImageBoundsFromContentAlignment( imageBoundsParams.ImageBounds.Size , imageBoundsParams.Bounds , imageBoundsParams.ImageAlign )); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint"></see> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"></see> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; Rectangle bounds = this.ClientRectangle; if (bounds.Width > 0 && bounds.Height > 0) { using (Brush brush = new LinearGradientBrush(bounds, this.StartGradientColor, this.EndGradientColor, this.GradientDirection)) { g.FillRectangle(brush, bounds); } if (this.Watermark != null) { Rectangle watermarkBounds = NuGenControlPaint.ImageBoundsFromContentAlignment( this.WatermarkSize , this.ClientRectangle , this.WatermarkAlign ); if (this.Desaturate) { NuGenWatermarkRenderer.DrawDesaturatedWatermark( g , this.Watermark , watermarkBounds , this.WatermarkTransparency ); } else { NuGenWatermarkRenderer.DrawWatermark( g , this.Watermark , watermarkBounds , this.WatermarkTransparency ); } } } }
/* * OnPaint */ /// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint"/> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"/> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; if (this.Image != null) { Rectangle imageBounds = this.ClientRectangle; switch (this.DisplayMode) { case NuGenDisplayMode.ActualSize: { if (this.AutoScrollPosition.X == 0 && this.AutoScrollPosition.Y == 0 && this.AutoScrollMinSize.Width <= this.ClientRectangle.Width && this.AutoScrollMinSize.Height <= this.ClientRectangle.Height ) { imageBounds = NuGenControlPaint.ImageBoundsFromContentAlignment( this.Image.Size , this.ClientRectangle , this.ImageAlign ); } else { imageBounds = new Rectangle( this.AutoScrollPosition.X , this.AutoScrollPosition.Y , this.Image.Width , this.Image.Height ); } break; } case NuGenDisplayMode.Zoom: { imageBounds = new Rectangle( (int)(this.AutoScrollPosition.X / _zoomFactor) , (int)(this.AutoScrollPosition.Y / _zoomFactor) , (int)(this.Image.Width * _zoomFactor) , (int)(this.Image.Height * _zoomFactor) ); float zoomFactor = (float)_zoomFactor; g.ScaleTransform(zoomFactor, zoomFactor); break; } case NuGenDisplayMode.ScaleToFit: { imageBounds = NuGenControlPaint.ScaleToFit(this.ClientRectangle, this.Image.Size); break; } } NuGenImagePaintParams imagePaintParams = new NuGenImagePaintParams(g); imagePaintParams.Bounds = imageBounds; imagePaintParams.Image = this.Image; imagePaintParams.State = this.StateTracker.GetControlState(); this.Renderer.DrawImage(imagePaintParams); } }