發表文章

目前顯示的是有「繪圖」標籤的文章

圖形縮放

利用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) 相關參考 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") 如果想要存到MemoryStream裡面可以參考下面程式碼,其實都是大同小異 Dim img As Image Dim B As...

繪製矩形

繪圖部分一直是我不熟悉的領域,最近想弄一些東西應該會來研究一下,下面這段程式在Form上面按住左鍵後移動滑鼠便會畫出矩形,算是第一步吧 ~ Dim BG As Bitmap Dim G As Graphics Dim IsMouseDown As Boolean = False Dim P_Start As New Point Private Sub frmEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Show() Application.DoEvents() BG = New Bitmap(PictureBox1.Width, PictureBox1.Height) G = Graphics.FromImage(BG) End Sub Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown IsMouseDown = True P_Start = e.Location End Sub Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove If IsMouseDown Then G.Clear(Color.Transparent) If e.X - P_Start.X > 0 Then If e.Y - P_Start.Y > 0 Then G.DrawRectangle(New Pen(Color.Pink, 2), _ New Rectangle( _ P_Start.X, P_Start.Y, e.X - P_Start.X, e.Y - P_Start.Y)) Else G.DrawRectangle(New Pen(Color.Pink, 2), _ New Rectangle( ...