翻转或旋转Word下载.docx
《翻转或旋转Word下载.docx》由会员分享,可在线阅读,更多相关《翻转或旋转Word下载.docx(21页珍藏版)》请在冰豆网上搜索。
set;
}
8.
Stride
9.
Width
10.
11.}
2.计算目标图像每像素的位置所用的抽象类(其实接口可以省略)
2.using
System.Collections.Generic;
3.using
System.Text;
5.namespace
6.{
abstract
class
RotateFlipDestinationBase
:
private
_width;
11.
12.
13.
get
return
14.
set
_width
=
value;
15.
16.
_height;
17.
18.
19.
20.
21.
_height
22.
23.
_stride;
24.
25.
26.
27.
28.
_stride
29.
30.
31.
32.
33.}
3.旋转180°
所用到的计算
Rotate180FlipNone
override
byteCountPercentPixel)
(Height
-
y
1)
*
+
(Width
x
byteCountPercentPixel;
14.}
4.旋转180°
再垂直翻转
Rotate180FlipY
5.旋转180°
Rotate270FlipNone
6.旋转90°
Rotate90FlipNone
7.旋转90°
再水平翻转
Rotate90FlipX
8.旋转90°
Rotate90FlipY
9.不进行旋转和翻转
RotateNoneFlipNone
10.垂直翻转
RotateNoneFlipY
11.静态旋转翻转类
4.using
System.Drawing;
5.using
System.Drawing.Imaging;
7.namespace
8.{
MyBitmap
static
Bitmap
RotateFlip(Bitmap
originalBitmap,
RotateFlipType
rotateFlipType)
byteCountsPercentPixel
GetByteCountsPercentPixel(originalBitmap.PixelFormat);
System.Drawing.Rectangle
originalBitmapRect
new
System.Drawing.Rectangle(0,
0,
originalBitmap.Width,
originalBitmap.Height);
BitmapData
originalBitmapData
originalBitmap.LockBits(originalBitmapRect,
ImageLockMode.ReadWrite,
originalBitmap.PixelFormat);
IntPtr
originalBitmapPtr
originalBitmapData.Scan0;
originalBitmapBytes
originalBitmapData.Stride
originalBitmap.Height;
byte[]
originalBitmapRgbValues
byte[originalBitmapBytes];
rotateFlipDestination
CreatRotateFlipDestination(originalBitmap,
rotateFlipType);
destinationBitmap
Bitmap(rotateFlipDestination.Width,
rotateFlipDestination.Height,
destinationBitmapRect
destinationBitmap.Width,
destinationBitmap.Height);
destinationBitmapData
destinationBitmap.LockBits(destinationBitmapRect,
destinationBitmapPtr
destinationBitmapData.Scan0;
destinationBitmapBytes
destinationBitmapData.Stride
destinationBitmap.Height;
destinationBitmapRgbValues
byte[destinationBitmapBytes];
rotateFlipDestination.Stride
destinationBitmapData.Stride;
33.
System.Runtime.InteropServices.Marshal.Copy(originalBitmapPtr,
originalBitmapRgbValues,
originalBitmapBytes);
34.
System.Runtime.InteropServices.Marshal.Copy(destinationBitmapPtr,
destinationBitmapRgbValues,
destinationBitmapBytes);
35.
36.
originalBitmapPos
0;
37.
destinationBitmapPos
38.
39.
for
(int
<
originalBitmapData.Height;
y++)
40.
41.
originalBitmapData.Width;
x++)
42.
43.
byteCountsPercentPixel;
44.
rotateFlipDestination.CalculatePos(x,
byteCountsPercentPixel);
45.
i
i++)
46.
47.
destinationBitmapRgbValues[destinationBitmapPos
i]
originalBitmapRgbValues[originalBitmapPos
i];
48.
49.
50.
51.
52.
System.Runtime.InteropServices.Marshal.Copy(destinationBitmapRgbValues,
destinationBitmapPtr,
53.
destinationBitmap.UnlockBits(destinationBitmapData);
54.
originalBitmap.UnlockBits(originalBitmapData);
55.
56.
destinationBitmap;
57.
58.
59.
CreatRotateFlipDestination(Bitmap
60.
61.
null;
62.
switch
(rotateFlipType)
63.
64.
case
RotateFlipType.RotateNoneFlipNone:
65.
//case
RotateFlipType.Rotate180FlipXY:
66.
RotateNoneFlipNone();
67.
rotateFlipDestination.Width
originalBitmap.Width;
68.
rotateFlipDestination.Height
69.
break;
70.
RotateFlipType.Rotate180FlipNone:
71.
RotateFlipType.RotateNoneFlipXY:
72.
Rotate180FlipNone();
73.
74.
75.
76.
RotateFlipType.Rotate180FlipY:
77.
RotateFlipType.RotateNoneFlipX:
78.
Ro