这个主题在Stack Overflow上多次被触及,但我的搜索仍然没有给我一个答案。
我正在寻找一个简单易用,非常基本的图像编辑库。我需要做的就是检查jpeg和png文件的大小,并将它们旋转90°的倍数。
我可以在VB.NET中开发我的应用程序,或者最好是VB5,我没有使用任何其他库。
我尝试了高级图像库(基于免费图像库),但我无法正确注册dll,我担心在分发应用程序时我也会遇到问题。
有什么更简单的东西吗?如果它不是免费的,只要费用合理,就可以了。
感谢您的帮助和道歉,如果答案已经在其他地方并且我看不到它
答案 0 :(得分:1)
public static Bitmap RotateImage(Image image, PointF offset, float angle)
{
int R1, R2;
R1 = R2 = 0;
if (image.Width > image.Height)
R2 = image.Width - image.Height;
else
R1 = image.Height-image.Width;
if (image == null)
throw new ArgumentNullException("image");
//create a new empty bitmap to hold rotated image
Bitmap rotatedBmp = new Bitmap(image.Width +R1+40, image.Height+R2+40);
rotatedBmp.SetResolution(image.HorizontalResolution, image.VerticalResolution);
//make a graphics object from the empty bitmap
Graphics g = Graphics.FromImage(rotatedBmp);
//Put the rotation point in the center of the image
g.TranslateTransform(offset.X + R1/2+20, offset.Y + R2/2+20);
//rotate the image
g.RotateTransform(angle);
//move the image back
g.TranslateTransform(-offset.X - R1 / 2-20, -offset.Y - R2 / 2-20);
//draw passed in image onto graphics object
g.DrawImage(image, new PointF(R1 / 2+20, R2 / 2+20));
return rotatedBmp;
}