winform 如何使picturebox 旋转
答案:1 悬赏:30 手机版
解决时间 2021-04-14 22:45
- 提问者网友:送舟行
- 2021-04-14 04:30
RT,就是说 使它水平旋转90。
最佳答案
- 五星知识达人网友:污到你湿
- 2021-04-14 05:04
//可以实现任意角度的旋转,旋转出现的角落空白可以选择填充的颜色。
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
namespace bitmaprerote
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static Bitmap KiRotate(Bitmap bmp, float angle, Color bkColor)
{
int w = bmp.Width + 2;
int h = bmp.Height + 2;
PixelFormat pf;
if (bkColor == Color.Transparent)
{
pf = PixelFormat.Format32bppArgb;
}
else
{
pf = bmp.PixelFormat;
}
Bitmap tmp = new Bitmap(w, h, pf);
Graphics g = Graphics.FromImage(tmp);
g.Clear(bkColor);
g.DrawImageUnscaled(bmp, 1, 1);
g.Dispose();
GraphicsPath path = new GraphicsPath();
path.AddRectangle(new RectangleF(0f, 0f, w, h));
Matrix mtrx = new Matrix();
mtrx.Rotate(angle);
RectangleF rct = path.GetBounds(mtrx);
Bitmap dst = new Bitmap((int)rct.Width, (int)rct.Height, pf);
g = Graphics.FromImage(dst);
g.Clear(bkColor);
g.TranslateTransform(-rct.X, -rct.Y);
g.RotateTransform(angle);
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
g.DrawImageUnscaled(tmp, 0, 0);
g.Dispose();
tmp.Dispose();
return dst;
}
private void button2_Click(object sender, EventArgs e)
{
Bitmap map = new Bitmap("F:\\hj.jpg");
this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
map = KiRotate(map, 30, Color.Pink);
pictureBox1.Image = map;
}
}
}
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Text;
using System.Windows.Forms;
namespace bitmaprerote
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static Bitmap KiRotate(Bitmap bmp, float angle, Color bkColor)
{
int w = bmp.Width + 2;
int h = bmp.Height + 2;
PixelFormat pf;
if (bkColor == Color.Transparent)
{
pf = PixelFormat.Format32bppArgb;
}
else
{
pf = bmp.PixelFormat;
}
Bitmap tmp = new Bitmap(w, h, pf);
Graphics g = Graphics.FromImage(tmp);
g.Clear(bkColor);
g.DrawImageUnscaled(bmp, 1, 1);
g.Dispose();
GraphicsPath path = new GraphicsPath();
path.AddRectangle(new RectangleF(0f, 0f, w, h));
Matrix mtrx = new Matrix();
mtrx.Rotate(angle);
RectangleF rct = path.GetBounds(mtrx);
Bitmap dst = new Bitmap((int)rct.Width, (int)rct.Height, pf);
g = Graphics.FromImage(dst);
g.Clear(bkColor);
g.TranslateTransform(-rct.X, -rct.Y);
g.RotateTransform(angle);
g.InterpolationMode = InterpolationMode.HighQualityBilinear;
g.DrawImageUnscaled(tmp, 0, 0);
g.Dispose();
tmp.Dispose();
return dst;
}
private void button2_Click(object sender, EventArgs e)
{
Bitmap map = new Bitmap("F:\\hj.jpg");
this.pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
map = KiRotate(map, 30, Color.Pink);
pictureBox1.Image = map;
}
}
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯