为什么我用以下的代码,旋转后图片变小了?
旋转九十度后,图片显示不全
double fangle = (angle * Math.PI) / 180;
int rwidth = System.Convert.ToInt32(_canvas.Height * Math.Sin(fangle) + _canvas.Width * Math.Cos(fangle));
int rheight = System.Convert.ToInt32(_canvas.Width * Math.Sin(fangle) + _canvas.Height * Math.Cos(fangle));
Bitmap bmp = new Bitmap(rwidth, rheight);
Graphics pic = Graphics.FromImage(bmp);
pic.TranslateTransform(rwidth / 2F, 0);
pic.RotateTransform(angle, MatrixOrder.Prepend);
pic.DrawImage(_canvas, new Rectangle(1, 1, _canvas.Width, _canvas.Height), new Rectangle(1, 1, rheight, rheight), GraphicsUnit.Pixel);
旋转九十度后,图片显示不全
double fangle = (angle * Math.PI) / 180;
int rwidth = System.Convert.ToInt32(_canvas.Height * Math.Sin(fangle) + _canvas.Width * Math.Cos(fangle));
int rheight = System.Convert.ToInt32(_canvas.Width * Math.Sin(fangle) + _canvas.Height * Math.Cos(fangle));
Bitmap bmp = new Bitmap(rwidth, rheight);
Graphics pic = Graphics.FromImage(bmp);
pic.TranslateTransform(rwidth / 2F, 0);
pic.RotateTransform(angle, MatrixOrder.Prepend);
pic.DrawImage(_canvas, new Rectangle(1, 1, _canvas.Width, _canvas.Height), new Rectangle(1, 1, rheight, rheight), GraphicsUnit.Pixel);
解决方案 »
- 关于C# API Windows输入消息
- 这段vB代码如何转换
- InvokeMember("click")
- 如何解决这个问题:allowDefinition='MachineToApplication'
- 关于SQL字浮串比较大小的原理!
- 程序报错,高手救命,没有分了
- [Q]+运算是如何处理的?
- 如何将一个对象转换成Stream
- 一个数组的问题?????????????????????????????????????????
- ReportView 转到报表功能无法在客户端实现求解
- 求助:SqlParameterCollection 中未包含带有 ParameterName“SmSdriW”的 SqlParameter
- 一个关于安装程序的制作问题!!解决者给100分 其它顶的有分
int height = image.Height;
#region
if(type==0)
{
for(int i=0;i<width/2;i++)
{
for(int j=0;j<height;j++)
{
if(i!=width-1-i)
{
Color color = image.GetPixel(i,j);
image.SetPixel(i,j,image.GetPixel(width-1-i,j));
image.SetPixel(width-1-i,j,color);
}
}
}
}
else if(type==1)
{
for(int i=0;i<width;i++)
{
for(int j=0;j<height/2;j++)
{
if(j!=height-1-j)
{
Color color = image.GetPixel(i,j);
image.SetPixel(i,j,image.GetPixel(i,height-1-j));
image.SetPixel(i,height-1-j,color);
}
}
}
}
else if(type==2)
{
for(int i=0;i<width;i++)
{
for(int j=0;j<height/2;j++)
{
Color color = image.GetPixel(i,j);
image.SetPixel(i,j,image.GetPixel(width-1-i,height-1-j));
image.SetPixel(width-1-i,height-1-j,color);
}
}任意翻转
Dim bmp As New Bitmap(Me.PictureBox1.Image.Width, Me.PictureBox1.Image.Height)
Dim g As Drawing.Graphics = Drawing.Graphics.FromImage(bmp)
Dim m As New Drawing2D.Matrix
Dim m1 As New Drawing2D.Matrix
Dim m2 As New Drawing2D.Matrix(1, 0, 0, -1, 0, bmp.Height) '*** 反射并平移
m1.Multiply(m2)
g.Transform = m1
g.DrawImage(Me.PictureBox1.Image, 0, 0)
Me.PictureBox2.Image = bmp
如果只是旋转90度,为什么还要用到PI和三角函数??长和高对调一下就好了。还有,你那个angle也不要去算吧,直接输入90.0F
this.pictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone);
this.pictureBox1.Refresh();
this.pictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone);
int i=this.pictureBox1.Height;
this.pictureBox1.Height=this.pictureBox1.Width;
this.pictureBox1.Width=i;
this.pictureBox1.Refresh();