Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

I think i found a glitch in the GDI

$
0
0

This code below seems to trigger a glitch in the GDI.  What happens is I load a bitmap file from disk into a streamreader, then pass the base stream to the Bitmap.fromStream() method.  This method returns a bitmap.  I then close the streamreader and then attempt to save the bitmap back out to a file.

This crashes with a generic error in GDI exception.  This says to me that the streamreader object got incorporated into the Bitmap object and was being used in the save operation.  I wouldn't expect that to work that way.  Is this a glitch in GDI or something I have to be on the look out for when using the fromStream bitmap creator.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gdiGlitchTest
{
    class Program
    {
        static void Main(string[] args)
        {
            System.IO.StreamReader sr = new System.IO.StreamReader("test1.jpg");
            System.Drawing.Bitmap temp = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(sr.BaseStream);
            sr.Close();
            temp.Save("out.jpg", System.Drawing.Imaging.ImageFormat.Jpeg); //this crashes with GDI+ exception
        }
    }
}


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>