在VB.NET中,怎样把picturebox的图片旋转后进行保存

rorge 2005-08-11 02:52:14
在picturebox中有一图片,picbox.image
我用下面的语句实现旋转
picLicense.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
我暂时把原图假设为img1,旋转后的图片为img2
如果用pivbox.image.save()保存的话,那么保存下在的图片还是img1,而不是 img2
因为执行picLicense.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)后,
picbox.image仍旧是img1,而不是img2。
怎样才能得到img2呢,并保存下来。
如有别的方法,也请赐教。
望高手帮忙解决一下,谢谢!

...全文
1638 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
rorge 2005-08-17
  • 打赏
  • 举报
回复
不是显示,是怎样放大和缩小
不务正 2005-08-16
  • 打赏
  • 举报
回复
'Function to Display Image
Private Sub ShowImage(ByVal s As String)
cn = New SqlClient.SqlConnection(SqlConnection1.ConnectionString)
cn.Open()
Dim str As String = "SELECT photo FROM Photos WHERE name='" & s & "'"
Dim cmd As New SqlClient.SqlCommand(str, cn)
TextBox1.Text = s
Dim b() As Byte
b = cmd.ExecuteScalar()
If (b.Length > 0) Then
Dim stream As New MemoryStream(b, True)
stream.Write(b, 0, b.Length)
DrawToScale(New Bitmap(stream))
stream.Close()
End If
cn.Close()
End Sub
rorge 2005-08-16
  • 打赏
  • 举报
回复
图片已经保存在数据库中,我只想把从数据库中取出来的显示在picturebox里的图片,能通过事件使其放大和缩小,请问怎么实现
sx_lxh 2005-08-13
  • 打赏
  • 举报
回复
bmpTarget = New Bitmap(, Drawing.Imaging.PixelFormat.Format24bppRgb)
这条语句有问题啊,提示“使用了无效参数”
我先dim iwidth,iheight as integer,还是一样,我用0代替iWidth, iHeight也一样

----------------------------------------
iWidth, iHeight还有 g.DrawImage(imgSource, New Rectangle(0, 0, x, y)) 中的x,y均为图片的宽和高。



hamadou 2005-08-12
  • 打赏
  • 举报
回复
不用那么样设置,因为对image来说你的缩放应该操作于graphics对象,而不是简单地让pictruebox控件来 设置SizeMode
Dim image = Me.PictureBox1.Image
Dim g As Graphics = Me.PictureBox1.CreateGraphics
g.DrawImage(image, New Rectangle(0, 0, image.width * 2, image.height * 2))
rorge 2005-08-12
  • 打赏
  • 举报
回复
这样放大,那图片就失真的,我的意思是在不失真的前提下,能不能放大和缩小
hamadou 2005-08-12
  • 打赏
  • 举报
回复
为什么还要去用picturebox.creategraphic来绘制呢,如果只是想在picturebox上显示扩大或者缩小后的图片那么可以使用该方法,但是相反,你要是想把图片显示并且要存储,最好就直接用创建新image对象的方法:
Dim bitmap As Bitmap = bitmap.FromFile("f:\1.jpg")
Dim image As New Bitmap(bitmap, bitmap.Width / 2, bitmap.Height / 2)
Me.PictureBox1.Image = image
image.Save("f:\3.jpg")
rorge 2005-08-12
  • 打赏
  • 举报
回复
bmpTarget = New Bitmap(iWidth, iHeight, Drawing.Imaging.PixelFormat.Format24bppRgb)
这条语句有问题啊,提示“使用了无效参数”
我先dim iwidth,iheight as integer,还是一样,我用0代替iWidth, iHeight也一样
rorge 2005-08-12
  • 打赏
  • 举报
回复
再请问一下,用DrawImage()方法所画图象显示在picturebox1中,但原图仍存在于picturebox1中,两者会一起显示,怎样才能使显示缩小的图象的同时,不显示原图。
ConanKid 2005-08-11
  • 打赏
  • 举报
回复
放大缩小的问题:

Private ImageHeight As Short
Private ImageWidth As Short

'点击一次放大两倍
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
Me.PictureBox1.Width = ImageWidth * 2
Me.PictureBox1.Height = ImageHeight * 2
ImageWidth = Me.PictureBox1.Width
ImageHeight = Me.PictureBox1.Height

'Me.PictureBox1.Refresh()
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
ImageWidth = Me.PictureBox1.Width
ImageHeight = Me.PictureBox1.Height
End Sub
rorge 2005-08-11
  • 打赏
  • 举报
回复
谢谢,我也发现了,不知道刚才哪里没弄好。
我还想问一下,怎样才能让图片按比例缩小来显示
sx_lxh 2005-08-11
  • 打赏
  • 举报
回复
dim bmptarget as bitmap
bmpTarget = New Bitmap(iWidth, iHeight, Drawing.Imaging.PixelFormat.Format24bppRgb) '创建目标空画布
g = Graphics.FromImage(bmpTarget) '创建目标空画布指针
imgSource = Image.FromFile("c:\1.jpg") '图像源
'旋转
imgSource.RotateFlip(RotateFlipType.Rotate90FlipNone)
g.DrawImage(imgSource, New Rectangle(0, 0, x, y)) '图像源到目标空画布
imgSource.Dispose() : imgSource = Nothing '释放源图像
‘保存
bmpTarget.Save(c"\2.jpg", Imaging.ImageFormat.Jpeg) '目标画布存储
ConanKid 2005-08-11
  • 打赏
  • 举报
回复
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.PictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
Me.PictureBox1.Refresh()
Me.PictureBox1.Image.Save("c:\abcdfdfd.ico")
End Sub

我试了一下,保存下来的是旋转后的效果,与你说的不符

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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