473,383 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

bitmap resize

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
Nov 21 '05 #1
2 4516
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.HighQualityBic ubic

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

Me.PictureBox1.Image = bmp2

"Peter Proost" <pp*****@nospam.hotmail.com> wrote in message
news:Oz*************@TK2MSFTNGP12.phx.gbl:
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


Nov 21 '05 #2
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
"scorpion53061" <ad***@nospamherekjmsolutions.com> wrote in message
news:#x**************@TK2MSFTNGP10.phx.gbl...
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.HighQualityBic ubic

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

Me.PictureBox1.Image = bmp2

"Peter Proost" <pp*****@nospam.hotmail.com> wrote in message
news:Oz*************@TK2MSFTNGP12.phx.gbl:
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

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: obj | last post by:
Dear all: My english is poor.forgive me. i use GDI+ class in my MFC program.I want to do resize the Bitmap.But I have a importance point of time of execution of Resize Bitmap. I use c# to...
3
by: Bradford | last post by:
I have an Windows application that displays lots of different colored lines in a Panel by using the Graphics.DrawLine method. The location and length of each line comes from a database query that...
3
by: news | last post by:
Hi Guys, Sorry if this is an obvious question but Im trying to rotate a bitmap and then save it. So far Ive only found how to rotates a Graphic but I can't find how to save it. I also want to...
1
by: Manuel Adam | last post by:
Hello! I am using an web application to resize some JPG files. First I use WebClient to download the Image from the Web. Then I use the Bitmap Class to Save it as a different file. Later I...
2
by: active | last post by:
Problem: The PictureBox display appears to have the image cut off. I.e., the image bottom does not display although the PictureBox has room for it. It occurred to me that what was displayed was...
1
by: WB | last post by:
Hi, I have a helper class that has a method to resize images. It takes the virtual path of an image and resize it to a specified dimension like this. public void ResizeImageTest(string...
0
by: Henry Padilla | last post by:
I'm writing an app that creates a bitmap of a map (land, trees, ocean). The resolution of the map is ~84x52 (it can change but will get no larger than 256x128). Since this is so small I resize...
12
by: tjonsek | last post by:
I get a generic error (not very helpful) when attempting to save a re-sized image back to its original location. Here is the code snippet: Dim g As System.Drawing.Image =...
4
by: ShadowLocke | last post by:
I have a small program that resizes a bitmap according to mouse location. (see me talking to myself in this forum: http://bytes.com/forum/thread795956.html) So every time the mouse moves it...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.