必须有一个更简单的方法 [英] There has to be an easier way
问题描述
嗨组我昨天已经发布了这个问题,我找到了一个
解决方案,但是我不喜欢它,在我的意见中必须要更容易方式
这样做,但我找不到,我希望有人可以帮我这个。只需
复制粘贴代码的空表格并按下绘图按钮,然后按
调整大小按钮,看看它做了什么,但我只是不喜欢我的方式
它,我似乎找不到更容易的方式
公共类Form1
继承System.Windows.Forms.Form
#Region" Windows窗体设计器生成的代码
Public Sub New()
MyBase.New()
' 'Windows窗体设计器需要此调用。
InitializeComponent()
''在InitializeComponent()调用后添加任何初始化
< br $>
结束子
''表格覆盖处理以清理组件列表。
受保护的重载覆盖子处理(ByVal处理为布尔)
如果处置那么
如果不是(组件什么都没有)那么
components.Dispose()
结束如果
结束如果
MyBase.Dispose(处置)
结束子
'' Windows窗体设计器要求
私有组件As System.ComponentModel.IContainer
''注意:Windows窗体设计器需要以下过程
''可以使用Windows窗体设计器修改它。
''不要莫使用代码编辑器来消除它。
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(34,42)
Me.PictureBox1.Name =" PictureBox1"
Me.PictureBox1。 Size = New System.Drawing.Size(301,301)
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
''
''PictureBox2
''
Me.PictureBox2.Location = New System.Drawing.Point(418,42)
Me.PictureBox2.Name =" PictureBox2"
Me.PictureBox2.Size = New System.Drawing.Size(140,140)
Me.PictureBox2.TabIndex = 1
Me.PictureBox2.TabStop = Fa lse
''
''Button1
''
Me.Button1.Location = New System.Drawing .Point(94,10)
Me.Button1.Name =" Button1"
Me.Button1.TabIndex = 2
Me。 Button1.Text =" Draw"
''
''Button2
''
Me.Button2 .Location = New System.Drawing.Point(198,10)
Me.Button2.Name =" Button2"
Me.Button2.Size = New System.Drawing .Size(72,22)
Me.Button2.TabIndex = 3
Me.Button2.Text =" Resize"
Me。 Button2.Visible = False
''
''Form1
''
Me.AutoScaleBaseSize =新系统.Drawing.Size(5,13)
Me.ClientSize = New System.Drawing.Size(740,419)
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 Button1_Click(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理Button1.Click
试试
Dim g As Graphics
Dim b As New Bitmap(301,301)
g = Graphics.FromImage(b)
g.Clear(Color.White)
g.DrawLine(New Pen(Color.Black),0,0,300,0)
g.DrawLine(New笔(Color.Black),0,300,0,0)
g.DrawLine(New Pen(Color.Black),300,0,300,300)
g.DrawLine(New Pen(Color.Black),300,300,0,300)
PictureBox1.Image = b
g.Dispose()
Button2.Visible = True
Catch ex As Exception
MsgBox(ex.ToString)
结束尝试
End Sub
Private Sub Button2_Click(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理Button2.Click
尝试
Dim g 2 As Graphics
Dim scale As Double
scale = 301/128
Dim bNew As New Bitmap(CInt(301 / scale)+ 1 ,CInt(301 /比例)
+ 1)
g2 = Graphics.FromImage(bNew)
g2.Clear(Color.White)
g2.PixelOffsetMode =
Drawing.Drawing2D.PixelOffsetMode.HighQuality
g2.DrawImage(PictureBox1.Image,New Rectangle(0,0, CInt(301 /
PictureBox1.Image.Height,GraphicsUnit.Pixel )
black(bNew)
PictureBox2.Image = bNew
g2.Dispose()
Catch ex As例外
ex.ToString()
结束尝试
结束子
Private Sub black(ByVal pBitmap As Bitmap)
Dim row,col As Integer
For row = 0 To 128
for col = 0 To 128
如果pBitmap.GetPixel(col,row).Name<> " FFFFFFFF"然后
pBitmap.SetPixel(col,row,Color.Black)
结束如果
下一页
下一页
结束子
结束班
Hi group I already posted this problem yesterday, and I''ve found a
"solution", but I don''t like it, in my opnion there has to be an easier way
to do this, but I can''t find, I hope some one can help me with this. Just
copy paste the code in an empty form and press the draw button, then press
the resize button to see what it does, but I just don''t like the way I do
it, and I can''t seem to find an easier way
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(34, 42)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(301, 301)
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
''
''PictureBox2
''
Me.PictureBox2.Location = New System.Drawing.Point(418, 42)
Me.PictureBox2.Name = "PictureBox2"
Me.PictureBox2.Size = New System.Drawing.Size(140, 140)
Me.PictureBox2.TabIndex = 1
Me.PictureBox2.TabStop = False
''
''Button1
''
Me.Button1.Location = New System.Drawing.Point(94, 10)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 2
Me.Button1.Text = "Draw"
''
''Button2
''
Me.Button2.Location = New System.Drawing.Point(198, 10)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(72, 22)
Me.Button2.TabIndex = 3
Me.Button2.Text = "Resize"
Me.Button2.Visible = False
''
''Form1
''
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(740, 419)
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 Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim g As Graphics
Dim b As New Bitmap(301, 301)
g = Graphics.FromImage(b)
g.Clear(Color.White)
g.DrawLine(New Pen(Color.Black), 0, 0, 300, 0)
g.DrawLine(New Pen(Color.Black), 0, 300, 0, 0)
g.DrawLine(New Pen(Color.Black), 300, 0, 300, 300)
g.DrawLine(New Pen(Color.Black), 300, 300, 0, 300)
PictureBox1.Image = b
g.Dispose()
Button2.Visible = True
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Try
Dim g2 As Graphics
Dim scale As Double
scale = 301 / 128
Dim bNew As New Bitmap(CInt(301 / scale) + 1, CInt(301 / scale)
+ 1)
g2 = Graphics.FromImage(bNew)
g2.Clear(Color.White)
g2.PixelOffsetMode =
Drawing.Drawing2D.PixelOffsetMode.HighQuality
g2.DrawImage(PictureBox1.Image, New Rectangle(0, 0, CInt(301 /
scale), CInt(301 / scale)), 0, 0, PictureBox1.Image.Width,
PictureBox1.Image.Height, GraphicsUnit.Pixel)
black(bNew)
PictureBox2.Image = bNew
g2.Dispose()
Catch ex As Exception
ex.ToString()
End Try
End Sub
Private Sub black(ByVal pBitmap As Bitmap)
Dim row, col As Integer
For row = 0 To 128
For col = 0 To 128
If pBitmap.GetPixel(col, row).Name <> "ffffffff" Then
pBitmap.SetPixel(col, row, Color.Black)
End If
Next
Next
End Sub
End Class
推荐答案
彼得,
取决于你想做什么,你真的想拍一张小图片吗?或者你想在一个较小的图片框中显示图片。
当我想剪切图片的某些部分时,我使用了一种这种方法。
当它以另一种方式显示时,我会使用它的sizemode
picturebox。
Cor
Peter,
Depends on what you want to do, do you really want to make a smaller picture
or do you want to show the picture in a smaller picturebox.
I use a kind of this methode when i want to cut of parts of the picture.
When it would be for showing in another way I would use the sizemode of the
picturebox.
Cor
我真的想要调整图片大小然后保存它,因为我需要128 * 128的
图片
grtz彼得
" Cor Ligthert" <无************ @ planet.nl>在消息中写道
新闻:OE ************* @ TK2MSFTNGP09.phx.gbl ...
I realy want to resize the picture and then save it, because I need the
picture at 128*128
grtz Peter
"Cor Ligthert" <no************@planet.nl> wrote in message
news:OE*************@TK2MSFTNGP09.phx.gbl...
彼得,
取决于你想做什么,你真的想制作一张更小的
图片,还是想在更小的图片框中显示图片。
我用的是一种这个方法当我想剪切图片的部分时。
当它以另一种方式显示时,我将使用
尺寸模式的图片框。
Peter,
Depends on what you want to do, do you really want to make a smaller picture or do you want to show the picture in a smaller picturebox.
I use a kind of this methode when i want to cut of parts of the picture.
When it would be for showing in another way I would use the sizemode of the picturebox.
Cor
彼得,
而不是缩略图,因为这是一个特殊的方法?
Cor
Peter,
And not a thumbnail, because therefore is a special method?
Cor
这篇关于必须有一个更简单的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!