반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | 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 ImageSize { public partial class Form1 : Form { Bitmap bitmapOri = null; public Form1() { InitializeComponent(); this.label1.Text = this.trackBar1.Value + "%"; this.pictureBox1.Image = bitmapOri = Properties.Resources._9996A8335B53615E1E; } private void trackBar1_Scroll(object sender, EventArgs e) { this.label1.Text = this.trackBar1.Value + "%"; this.pictureBox1.Image = ResizeImage(); } private Bitmap ResizeImage() { int width = (bitmapOri.Width * this.trackBar1.Value) / 100; int height = (bitmapOri.Height * this.trackBar1.Value) / 100; Rectangle rect = new Rectangle(0, 0, width, height); Bitmap bitmap = new Bitmap(width, height); bitmap.SetResolution(bitmapOri.HorizontalResolution, bitmap.VerticalResolution); using (var g = Graphics.FromImage(bitmap)) { 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(bitmapOri, rect, 0, 0, bitmapOri.Width, bitmapOri.Height, GraphicsUnit.Pixel, wrapmode); } } return bitmap; } } } | cs |
실행
'프로그래밍 > C#' 카테고리의 다른 글
[C#]cmd정보 명령 실행하고 결과 가져오기 (0) | 2018.08.09 |
---|---|
[C#]Tuple 7.0부터 사용가능 (0) | 2018.07.26 |
[C#]Image에 흰색 지우기 (0) | 2018.07.22 |
[C#]텍스트 읽어들이기 (0) | 2018.07.17 |
[C#]동그란 이미지 만들기 (0) | 2018.07.01 |