비트맵 리사이징 메써드
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static Bitmap ResizeBitmap(Bitmap bmp, float ratio, InterpolationMode im)
{
int w = bmp.Width;
int h = bmp.Height;
Bitmap tmp = new Bitmap((int)(w * ratio), (int)(h * ratio), bmp.PixelFormat);
Graphics g = Graphics.FromImage(tmp);
g.InterpolationMode = im;
g.DrawImage(bmp, new RectangleF(0f, 0f, w * ratio, h * ratio));
g.Dispose();
return tmp;
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(@"C:\Users\sgi320\Desktop\lena.bmp");
Bitmap tmp;
int w, h;
float ratio = 0.5f;
Graphics g = this.CreateGraphics();
tmp = ResizeBitmap(bmp, ratio, InterpolationMode.Bicubic);
g.DrawImageUnscaled(tmp, 5, 5);
w = tmp.Width;
h = tmp.Height;
tmp.Dispose();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static Bitmap ResizeBitmap(Bitmap bmp, float ratio, InterpolationMode im)
{
int w = bmp.Width;
int h = bmp.Height;
Bitmap tmp = new Bitmap((int)(w * ratio), (int)(h * ratio), bmp.PixelFormat);
Graphics g = Graphics.FromImage(tmp);
g.InterpolationMode = im;
g.DrawImage(bmp, new RectangleF(0f, 0f, w * ratio, h * ratio));
g.Dispose();
return tmp;
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap bmp = new Bitmap(@"C:\Users\sgi320\Desktop\lena.bmp");
Bitmap tmp;
int w, h;
float ratio = 0.5f;
Graphics g = this.CreateGraphics();
tmp = ResizeBitmap(bmp, ratio, InterpolationMode.Bicubic);
g.DrawImageUnscaled(tmp, 5, 5);
w = tmp.Width;
h = tmp.Height;
tmp.Dispose();
}
}
}
댓글
댓글 쓰기