save image from picturebox in stream format

后端 未结 1 996
借酒劲吻你
借酒劲吻你 2021-01-15 16:11

i wanna save a picture that loaded in a picturebox to stream .when i save in png format it work properly but when i want save it in other formats i get

相关标签:
1条回答
  • 2021-01-15 16:26

    Try this method:

    public Stream ImageToStream(Image image, System.Drawing.Imaging.ImageFormat format)
    {
        MemoryStream ms = new MemoryStream();
        image.Save(ms, format);
        return  ms;
    }
    

    and use it:

    using(Stream stream = ImageToStream(pictureBox1.Image, 
                               System.Drawing.Imaging.ImageFormat.Gif))
    {
        ...
    }
    
    0 讨论(0)
提交回复
热议问题