代碼:
private void button
_Click(object sender
EventArgs e)
{
try
{
int width = this
pictureBox
Width; //圖像寬度
int height = this
pictureBox
Height; //圖像高度
Graphics g = this
panel
CreateGraphics();
g
Clear(Color
Gray);
Bitmap bitmap = new Bitmap(width
height);
int x =
;
while (x <= height /
)
{
for (int i =
; i <= width
; i++)
{
bitmap
SetPixel(i
x
MyBitmap
GetPixel(i
x));
}
for (int i =
; i <= width
; i++)
{
bitmap
SetPixel(i
height
x
MyBitmap
GetPixel(i
height
x
));
}
x++;
this
panel
Refresh();
g
DrawImage (bitmap
);
System
Threading
Thread
Sleep(
);
}
}
catch (Exception ex)
{
MessageBox
Show(ex
Message
信息提示
);
}
}
三 以四周擴散的方式顯示圖像
原理: 首先設置圖像顯示的位置 然後按高度和寬度的比例循環輸出 直到高度和寬度為原始大小
代碼:
private void button
_Click(object sender
EventArgs e)
{
try
{
int width = this
MyBitmap
Width; //圖像寬度
int height = this
MyBitmap
Height; //圖像高度
//取得Graphics對象
Graphics g = this
panel
CreateGraphics();
g
Clear(Color
Gray); //初始為全灰色
for (int i =
; i <= width /
; i++)
{
int j = Convert
ToInt
(i*(Convert
ToSingle(height) / Convert
ToSingle(width)));
Rectangle DestRect = new Rectangle(width /
i
height/
j
* i
*j);
Rectangle SrcRect = new Rectangle(
MyBitmap
Width
MyBitmap
Height);
g
DrawImage(MyBitmap
DestRect
SrcRect
GraphicsUnit
Pixel);
System
Threading
Thread
Sleep(
);
}
}
catch (Exception ex)
{
MessageBox
Show(ex
Message
信息提示
);
}
}
[] [] [] [] [] [] [] [] [] []
From:http://tw.wingwit.com/Article/program/net/201311/14937.html