求救,保存不了图片调整后的效果

zhi4221cn 2008-03-27 08:37:14
Public Class Piccl

Dim Bl As Single = 1

Dim Op As New OpenFileDialog

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click

Op.Filter = "图片(*.jpg)|*.jpg|图片(*.gif)|*.gif|图片(*.bmp)|*.bmp"
If Op.ShowDialog <> Windows.Forms.DialogResult.OK Then Exit Sub

Dim Old_w As Integer = PictureBox1.Width
Dim Old_h As Integer = PictureBox1.Height

PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
PictureBox1.Image = System.Drawing.Image.FromStream(Op.OpenFile)
Dim Pw, Ph As Integer

Bl = 1

Pw = PictureBox1.Width
Ph = PictureBox1.Height

If Pw > Old_w Or Ph > Old_h Then
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
If Pw > Ph Then
Bl = Old_w / Pw
PictureBox1.Width = Old_w
PictureBox1.Height = Ph * Bl
Else
Bl = Old_h / Ph
PictureBox1.Height = Old_h
PictureBox1.Width = Pw * Bl
End If
End If

End Sub


Private Sub Piccl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
Me.DialogResult = Windows.Forms.DialogResult.No
Me.Close()
End Sub


Public Sub AdjustImage(ByVal e As PaintEventArgs)


Try
'Dim original As New Bitmap(PictureBox1.Image)
Dim original As System.Drawing.Bitmap = System.Drawing.Image.FromStream(Op.OpenFile)


Dim width As Integer = PictureBox1.Width
Dim height As Integer = PictureBox1.Height


Dim image As New Bitmap(original, New Size(width, height))
Dim imageAttributes As New System.Drawing.Imaging.ImageAttributes()



Dim colorMatrixElements As Single()() = { _
New Single() {CType(Me.nudB.Value / 100, Single), 0, 0, 0, 0}, _
New Single() {0, CType(Me.nudR.Value / 100, Single), 0, 0, 0}, _
New Single() {0, 0, CType(Me.nudG.Value / 100, Single), 0, 0}, _
New Single() {0, 0, 0, CType(Me.nudalpha.Value / 100, Single), 0}, _
New Single() {0, 0, 0, 0, 1}}

Dim colorMatrix As New System.Drawing.Imaging.ColorMatrix(colorMatrixElements)

imageAttributes.SetColorMatrix( _
colorMatrix, _
System.Drawing.Imaging.ColorMatrixFlag.Default, _
System.Drawing.Imaging.ColorAdjustType.Bitmap)

imageAttributes.SetGamma(CType(Me.nudgamma.Value / 100, Single), System.Drawing.Imaging.ColorAdjustType.Bitmap)


e.Graphics.DrawImage( _
image, _
New Rectangle(0, 0, width, height), _
0, 0, _
width, _
height, _
GraphicsUnit.Pixel, _
imageAttributes)

Catch Ex As Exception
'MsgBox(Ex.Message)
End Try

End Sub

Private Sub nudB_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudB.ValueChanged
PictureBox1.Invalidate()
End Sub

Private Sub nudG_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudG.ValueChanged
PictureBox1.Invalidate()
End Sub

Private Sub nudR_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudR.ValueChanged
PictureBox1.Invalidate()
End Sub

Private Sub nudalpha_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudalpha.ValueChanged
PictureBox1.Invalidate()
End Sub

Private Sub nudgamma_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles nudgamma.ValueChanged
PictureBox1.Invalidate()
End Sub

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
AdjustImage(e)
End Sub

Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
PictureBox1.Refresh()
Try
PictureBox1.Image.Save(Application.StartupPath() & "\temp_tz.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
'Picturebox1 正常显示调色后的效果,
'为什么Picturebox1总保存不了调色后的效果图版,
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

End Class
...全文
82 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
东方之珠 2008-03-31
  • 打赏
  • 举报
回复
up
cbm6666 2008-03-27
  • 打赏
  • 举报
回复
加一行 PictureBox1.AutoRedraw = True

嗷嗷叫的老马 2008-03-27
  • 打赏
  • 举报
回复
......................这样的帖子只能路过.
junki 2008-03-27
  • 打赏
  • 举报
回复
有所有源代码吗,我试试

809

社区成员

发帖
与我相关
我的任务
社区描述
VB 多媒体
社区管理员
  • 多媒体
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧