private Image ImageRoationAndOpacity(Image srcImage, int opacity, float AngleValue)
{
// 创建一个大小和图片相同的 Bitmap 对象
Bitmap bitmap = new Bitmap(srcImage.Width, srcImage.Height);
// 创建一个 Graphics 对象
Graphics graphics = Graphics.FromImage(bitmap);
// 将 Graphics 对象的坐标系原点移动到原来位置
graphics.TranslateTransform(bitmap.Width / 2, bitmap.Height / 2);
//旋转
graphics.RotateTransform(AngleValue);
// 将 Graphics 对象的坐标系原点移动到图片中心
graphics.TranslateTransform(-bitmap.Width / 2, -bitmap.Height / 2);
// 将原始图片绘制到 Bitmap 对象上,并指定透明度为 50%
ImageAttributes imageAttributes = new ImageAttributes();
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.Matrix33 = opacity/100f; // 设置透明度为 50%
imageAttributes.SetColorMatrix(colorMatrix);
graphics.DrawImage(srcImage, new Rectangle(0, 0, bitmap.Width, bitmap.Height), 0, 0, srcImage.Width, srcImage.Height, GraphicsUnit.Pixel, imageAttributes);
// 将 Bitmap 对象设置为控件的背景图片
//pictureBox1.BackgroundImage = bitmap;
将控件的背景颜色设置为透明
//pictureBox1.BackColor = Color.Transparent;
return (Image)bitmap.Clone();
}
winform动态修改图片任意旋转角度,修改透明度,位置,
最新推荐文章于 2023-10-06 17:36:49 发布