PDA

View Full Version : سوال: بزرگ و کوچک کردن تصویر در picture box در زمان اجرا



oliya24
یک شنبه 07 آذر 1389, 23:53 عصر
سلام دوستان من چطور میتونم تصویری که در picture box دارم رو در زمان اجرا تغیر اندازه بدم؟
ممنونم

mo.esmp
دوشنبه 08 آذر 1389, 02:38 صبح
این کد سایز عکس رو بر اساس درصد کوچیک و بزرگ میکنه البته با کمی تغییر خودت میتونی بر اساس اندازه پیکسل تغییرش بدی.

Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

Namespace resize
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub

Private _img As Bitmap

Private Sub Form1_Load(sender As Object, e As EventArgs)
_img = New Bitmap(pictureBox1.Image)
End Sub

Private Sub button1_Click(sender As Object, e As EventArgs)
Dim originalW As Integer = _img.Width
Dim originalH As Integer = _img.Height

Dim percentage As Single = CSng(Convert.ToInt32(textBox1.Text)) / 100


Dim resizedW As Integer = CInt(Math.Truncate(originalW * percentage))
Dim resizedH As Integer = CInt(Math.Truncate(originalH * percentage))

Dim bmp As New Bitmap(resizedW, resizedH)


Dim graphic As Graphics = Graphics.FromImage(bmp)
graphic.InterpolationMode = InterpolationMode.HighQualityBicubic
graphic.DrawImage(_img, 0, 0, resizedW, resizedH)

graphic.Dispose()

pictureBox1.Image = bmp
End Sub
End Class
End Namespace