Re-size Image using C# (Trackbar, Panel and PictureBox)
This video shows how to re-size image using C# (.NET Framework). It uses two trackbars, panel and picturebox controls.
resize image using java: https://youtu.be/N_jddMMhzqc
resize image using Objective-C: https://youtu.be/gTtXEfEbH0Y
Enjoy!!!
don’t forget to subscribe on YouTube as more code coming.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace ResizeImage { public partial class Form1 : Form { Image target_image; int width; int height; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { target_image = Image.FromFile(@"C:\tl\test.jpg"); width = target_image.Width; height = target_image.Height; pic_ctl.Image = target_image; } private void trackBar1_Scroll(object sender, EventArgs e) { width = (target_image.Width * slider_h.Value) / 100; pic_ctl.Image = ResizeNow(width, height); } private void trackBar2_Scroll(object sender, EventArgs e) { height = (target_image.Height * slider_v.Value) / 100; pic_ctl.Image = ResizeNow(width, height); } private Bitmap ResizeNow(int target_width,int target_height) { Rectangle dest_rect=new Rectangle(0,0,target_width,target_height); Bitmap destImage=new Bitmap(target_width,target_height); destImage.SetResolution(target_image.HorizontalResolution, target_image.VerticalResolution); using (var g = Graphics.FromImage(destImage)) { g.CompositingMode = CompositingMode.SourceCopy; g.CompositingQuality = CompositingQuality.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; using (var wrapmode = new ImageAttributes()) { wrapmode.SetWrapMode(WrapMode.TileFlipXY); g.DrawImage(target_image, dest_rect, 0, 0, target_image.Width, target_image.Height, GraphicsUnit.Pixel, wrapmode); } } return destImage; } } }