PDA

View Full Version : سوال: مشکل با تغییر فرمت تصاویر



oliya24
پنج شنبه 12 آبان 1390, 01:33 صبح
سلام و خسته نباشید من میخوام با استفاده از متد save یه عکس رو تغییر فرمت بدم !
روند کار به این صورته که تصویر مورد نظر رو داخل پیکچر باکس نمایش میدیم و با زدن دکمه تغییر فرمت فرمت تصویر داخل پیکچر باکس رو عوض میکنیم من از این کد برای تغییر فرمت استفاده کردم ولی ایراد داشت
picturebox1.image.save("مسیر ذخیره شدن",system.draving.imaging.imageformat.icon)

alimanam
پنج شنبه 12 آبان 1390, 10:29 صبح
با سلام

از این کد میتونی استفاده کنی .


Public Class Form1

Private Function MakeIcon(ByVal img As Image, ByVal size As Integer, ByVal keepAspectRatio As Boolean) As Icon
Dim square As New Bitmap(size, size)
Dim g As Graphics = Graphics.FromImage(square)

Dim x, y, w, h As Integer

If (Not keepAspectRatio) OrElse img.Height = img.Width Then
y = 0
x = y
h = size
w = h
Else
Dim r As Single = CSng(img.Width) / CSng(img.Height)

If r > 1 Then
w = size
h = CInt(Fix(CSng(size) / r))
x = 0
y = (size - h) / 2
Else
w = CInt(Fix(CSng(size) * r))
h = size
y = 0
x = (size - w) / 2
End If
End If
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQua lityBicubic
g.DrawImage(img, x, y, w, h)
g.Flush()
Return Icon.FromHandle(square.GetHicon())
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim sFd As New SaveFileDialog
sFd.Filter = "Icon|*.ico"
sFd.FilterIndex = 1
If sFd.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim newIcon As Icon = MakeIcon(PictureBox1.Image, 32, True)
Dim fs As New IO.FileStream(sFd.FileName, IO.FileMode.CreateNew)
newIcon.Save(fs)
fs.Close()
End If

End Sub

End Class

موفق باشید ./