Zoom بر روی تصویر

' ----------------------------------------
' Required Imports :
'
' Microsoft.VisualBasic
' System
' System.Drawing
' System.Windows.Forms
' ----------------------------------------

' This code simulates a zoom effect with two
' bitmaps of the same size, where the second
' contains a zoomed center section of the first.
Dim bmp as Bitmap
Dim bmpZoom as Bitmap

' First call CreateBitmap, then call DefineZoom.
Sub CreateBitmap()
bmp = New Bitmap(75,75)
Dim g As Graphics = Graphics.FromImage(bmp)

Dim BlueBrush As New SolidBrush(Color.Blue)
Dim RedBrush As New SolidBrush(Color.Red)

Dim OuterRect As New Rectangle(0, 0, 200, 200)
g.FillRectangle(BlueBrush, OuterRect)

Dim InnerRect As New Rectangle(25, 25, 25, 25)
g.FillRectangle(RedBrush, InnerRect)

g.Dispose()
End Sub

Sub DefineZoom()
' Call this method after CreateBitmap
' from the constructor of your form.
bmpZoom = New Bitmap(bmp.Width, bmp.Height)
Dim g As Graphics = Graphics.FromImage(bmpZoom)

Dim srcRect As New Rectangle(CInt(bmp.Width / 4), CInt(bmp.Height / 4), _
CInt(bmp.Width / 2), CInt(bmp.Height / 2))
Dim dstRect As New Rectangle(0, 0, bmpZoom.Width, bmpZoom.Height)
g.DrawImage(bmp, dstRect, srcRect, GraphicsUnit.Pixel)
End Sub

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
e.Graphics.DrawImage(bmp, 0, 0)
e.Graphics.DrawImage(bmpZoom, 125, 0)

bmp.Dispose
bmpZoom.Dispose
MyBase.OnPaint(e)
End Sub
نظرات 0 + ارسال نظر
برای نمایش آواتار خود در این وبلاگ در سایت Gravatar.com ثبت نام کنید. (راهنما)
ایمیل شما بعد از ثبت نمایش داده نخواهد شد