bitmap resize

P

Peter Proost

Hi group I have the following piece of code that should resize the bitmap in
a picture box but it doesn't work as I tought it would. Can someone help me
with it?

thnx Peter


Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents PictureBox2 As System.Windows.Forms.PictureBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.PictureBox1 = New System.Windows.Forms.PictureBox()
Me.PictureBox2 = New System.Windows.Forms.PictureBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'PictureBox1
'
Me.PictureBox1.Location = New System.Drawing.Point(40, 36)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(401, 401)
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
'
'PictureBox2
'
Me.PictureBox2.Location = New System.Drawing.Point(498, 36)
Me.PictureBox2.Name = "PictureBox2"
Me.PictureBox2.Size = New System.Drawing.Size(129, 129)
Me.PictureBox2.TabIndex = 1
Me.PictureBox2.TabStop = False
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(40, 6)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 2
Me.Button1.Text = "Draw"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(122, 6)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 3
Me.Button2.Text = "Resize"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(886, 447)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button2,
Me.Button1, Me.PictureBox2, Me.PictureBox1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region

Private Sub resizePicture(ByVal hoogte As Integer, ByVal breedte As
Integer)
Dim schaal As Double

If hoogte > breedte Then
schaal = hoogte / 128
Else
schaal = breedte / 128
End If

Dim b As Bitmap
b = New Bitmap(CInt(breedte / schaal), CInt(hoogte / schaal))

Dim g As Graphics = Graphics.FromImage(b)
g.DrawImage(PictureBox1.Image, New Rectangle(0, 0, b.Width,
b.Height), 0, 0, PictureBox1.Image.Width, PictureBox1.Image.Height,
GraphicsUnit.Pixel)
g.Dispose()
PictureBox2.Image = b

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim b As New Bitmap(400, 400)
Dim g As Graphics = Graphics.FromImage(b)
Dim pen As New Pen(Color.Black)
g.DrawLine(pen, 0, 0, 399, 0)
g.DrawLine(pen, 399, 0, 399, 399)
g.DrawLine(pen, 399, 399, 0, 399)
g.DrawLine(pen, 0, 399, 0, 0)
g.Dispose()
PictureBox1.Image = b
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Call resizePicture(PictureBox1.Image.Height,
PictureBox1.Image.Width)
End Sub


End Class
 
S

scorpion53061

Dim bmp As New Bitmap( _
"C:\Lagoon1024x768.bmp" _
)
Dim bmp2 As New Bitmap( _
bmp.Width * 0.1, _
bmp.Height * 0.1, _
Imaging.PixelFormat.Format24bppRgb _
)
Dim g As Graphics = Graphics.FromImage(bmp2)

' Select/change interpolation mode here.
g.InterpolationMode = _
Drawing.Drawing2D.InterpolationMode.HighQualityBicubic

' Draw image using specified interpolation mode.
g.DrawImage(bmp, 0, 0, bmp2.Width, bmp2.Height)
g.Dispose()

Me.PictureBox1.Image = bmp2
 
P

Peter Proost

thnx for the quick reply but it didn't realy help me out, because, it just
draws a big black filled cube instead of a cube with a black border, maybe
it works ok for pictures, I don't now, but I'm doing some drawing and the
resizeing the drawed bitmap. See the code in my previous post.

Greetz Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top