GDI +中发生了一般错误。 VB.NET WHILE从picturebox保存图像 [英] A generic error occurred in GDI+. VB.NET WHILE saving image from picturebox

查看:95
本文介绍了GDI +中发生了一般错误。 VB.NET WHILE从picturebox保存图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请为我提供以下代码的解决方案,它在pic.save上显示GDI +错误。

please provide me solution for following code it shows GDI+ error on pic.save.

Public Class Form1<br />
    Dim open As OpenFileDialog<br />
    Dim i As String<br />
    Dim img As Image = Nothing<br />
    Dim pic As String<br />
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
    End Sub<br />
<br />
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br />
        open = New OpenFileDialog<br />
        open.Filter = "Image Files(*.jpg;*.jpeg;*.gif;*.bmp;*.png;*.tif)|*.jpg;*.gif;*.bmp;*.tif"<br />
        open.ShowDialog()<br />
        pic = open.FileName<br />
        Try<br />
            Dim fs As New System.IO.FileStream(pic, IO.FileMode.Open, IO.FileAccess.Read)<br />
            img = Image.FromStream(fs)<br />
            fs.Close()<br />
            fs.Dispose()<br />
            My.Computer.FileSystem.DeleteFile(pic)<br />
            emppic.Image = img<br />
        Catch ex As Exception<br />
            img = Nothing<br />
        End Try<br />
    End Sub<br />
<br />
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click<br />
        Dim img6 As Image<br />
        img6 = emppic.Image<br />
        Try<br />
            emppic.Image.Save("C:\C-tek\Images\Temp\1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)<br />
        Catch ex As Exception<br />
            MsgBox("File  Saving Error." + ex.ToString)<br />
        End Try<br />
    End Sub<br />
End Class



提前提前


thnks in advance

推荐答案

正如我上次告诉你的那样你发布这篇文章的时间: vb.net 2008一般错误发生在GDI +中。 [ ^ ]文档非常明确地说明你必须保持图片的生命周期开放。

你没有。



所以,你有两个选择:

1)保持流在图像的生命周期内打开。

2)将图像复制到另一个图像并在完成后处理原始流和图像。

这很简单:

As I told you last time you posted this: vb.net 2008 A generic error occurred in GDI+.[^] the documentation very clearly says that you must keep teh stream open for teh lifetime of the image.
You don't.

So, you have two options:
1) Keep the stream open for the life of the image.
2) Copy the image to another and Dispose of the original stream and image once you have done that.
That's easy:
Dim safeImage as New Bitmap(img)

您现在可以关闭并处理原始流和图像。



将来请稍微耐心一下......

You can now close and dispose the original stream and image.

In future, have a little patience please...

我有同样的问题,我解决了它创建路径我要保存并给予正确访问。

问候。
I had the same problem, I solved it creating the path were I want to save and giving right access.
Regards.


I面临同样的问题。在我的场景中,一切正常,但在保存图像时出现异常。问题是我正在保存带有特殊字符(\)的文件,这是不可接受的。现在它在更改文件名后工作正常。
I faced the same issue. In my scenario all are working fine,but getting exception when saving the image.the problem is i am saving the file with special character (\), which is not acceptable. now it is working fine after changed the file name.


这篇关于GDI +中发生了一般错误。 VB.NET WHILE从picturebox保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆