Click here to Skip to main content
15,881,248 members
Articles / Desktop Programming / Windows Forms

Zeta HTML Edit Control

Rate me:
Please Sign up or sign in to vote.
4.94/5 (60 votes)
9 Jul 2013CPOL3 min read 211.5K   20.8K   183  
A small wrapper class around the Windows Forms 2.0 WebBrowser control
namespace ZetaHtmlEditControl.Helper
{
	#region Using directives.
	// ----------------------------------------------------------------------
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;

    // ----------------------------------------------------------------------
	#endregion

	/////////////////////////////////////////////////////////////////////////

	/// <summary>
	/// Class for scaling an image.
	/// </summary>
	internal static class ImageScaler
	{
		#region Scaling.
		// ------------------------------------------------------------------

		/// <summary>
		/// Scale the given image to the given size.
		/// Uses a high interpolation mode quality.
		/// </summary>
		/// <param name="image">The image.</param>
		/// <param name="width">The width.</param>
		/// <param name="height">The height.</param>
		/// <returns></returns>
		public static Image ScaleImage(
			Image image,
			int width,
			int height)
		{
			// http://stackoverflow.com/questions/249587/high-quality-image-scaling-c-sharp
			// http://stackoverflow.com/questions/6821261/after-resizing-white-image-gets-gray-border

			// NO "using" here, because the image is returned (and
			// would be disposed by "using")!
			var result = new Bitmap(image, width, height);

			result.SetResolution(image.HorizontalResolution, image.VerticalResolution);

			using (var g = Graphics.FromImage(result))
			{
				g.CompositingQuality = CompositingQuality.HighQuality;
				g.InterpolationMode = InterpolationMode.HighQualityBicubic;
				g.SmoothingMode = SmoothingMode.HighQuality;
				g.PixelOffsetMode = PixelOffsetMode.HighQuality;

				var ia = new ImageAttributes();
				ia.SetWrapMode(WrapMode.TileFlipXY);

				g.DrawImage(
					image,
					new Rectangle(
						0,
						0,
						width,
						height),
					0,
					0,
					image.Width,
					image.Height,
					GraphicsUnit.Pixel,
					ia);

				return result;
			}
		}

		// ------------------------------------------------------------------
		#endregion
	}

	/////////////////////////////////////////////////////////////////////////
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer Zeta Software GmbH
Germany Germany
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.

➡️ Give me a tip 🙂

In his free time, he does climbing, running and mountain biking. In 2012 he became a father of a cute boy and in 2014 of an awesome girl.

Some cool, free software from us:

Windows 10 Ereignisanzeige  
German Developer Community  
Free Test Management Software - Intuitive, competitive, Test Plans.  
Homepage erstellen - Intuitive, very easy to use.  
Offline-Homepage-Baukasten

Comments and Discussions