摘要:圖形縮放
利用Image類別提供的相關功能或是利用PictureBox我們可以很簡單的載入或是顯示圖形在畫面上,那麼如果要縮/放圖形的話應該要怎麼做呢?請參考看看下面程式碼
- Dim img As Image
- img = Image.FromFile(Application.StartupPath & "\MyImages\9F.jpg")
- Dim G As Graphics = PictureBox2.CreateGraphics
- Dim P(2) As Point
- ''左上
- P(0) = New Point(0, 0)
- ''右上
- P(1) = New Point(100, 0)
- ''左下
- P(2) = New Point(0, 100)
- G.DrawImage(img, P)
Dim img As Image
img = Image.FromFile(Application.StartupPath & "\MyImages\9F.jpg")
Dim G As Graphics = PictureBox2.CreateGraphics
Dim P(2) As Point
''左上
P(0) = New Point(0, 0)
''右上
P(1) = New Point(100, 0)
''左下
P(2) = New Point(0, 100)
G.DrawImage(img, P)
相關參考
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.cht/cpref8/html/M_System_Drawing_Graphics_DrawImage_1_d482ade5.htm
或是可以直接上
MSDN查詢有關DrawImage相關的部分
如果要把修改後的圖存成另外的檔案可以參考下面程式碼
- Dim img As Image
- Dim B As New Bitmap(100, 100)
- img = Image.FromFile(Application.StartupPath & "\MyImages\9F.jpg")
- Dim G As Graphics = Graphics.FromImage(B)
- Dim P(2) As Point
- ''左上
- P(0) = New Point(0, 0)
- ''右上
- P(1) = New Point(100, 0)
- ''左下
- P(2) = New Point(0, 100)
- G.DrawImage(img, P)
- B.Save(Application.StartupPath & "\tmp.jpg")
Dim img As Image
Dim B As New Bitmap(100, 100)
img = Image.FromFile(Application.StartupPath & "\MyImages\9F.jpg")
Dim G As Graphics = Graphics.FromImage(B)
Dim P(2) As Point
''左上
P(0) = New Point(0, 0)
''右上
P(1) = New Point(100, 0)
''左下
P(2) = New Point(0, 100)
G.DrawImage(img, P)
B.Save(Application.StartupPath & "\tmp.jpg")
如果想要存到MemoryStream裡面可以參考下面程式碼,其實都是大同小異
- Dim img As Image
- Dim B As New Bitmap(100, 100)
- img = Image.FromFile(Application.StartupPath & "\MyImages\9F.jpg")
- Dim G As Graphics = Graphics.FromImage(B)
- Dim P(2) As Point
- ''左上
- P(0) = New Point(0, 0)
- ''右上
- P(1) = New Point(100, 0)
- ''左下
- P(2) = New Point(0, 100)
- G.DrawImage(img, P)
- Dim MS As New IO.MemoryStream
- B.Save(MS, Imaging.I