SiamIT
Well-known member
- Joined
- Aug 3, 2021
- Messages
- 53
- Programming Experience
- 5-10
I am facing a weird issue, i need to load GIF image/picture from memory to picture box. It's works fine for non GIF picture, but for GIF it throws GDI error.
here is my test codes to show you the error
any idea why is this happening?
thanks in advance
best regards
C#:
A generic error occurred in GDI+.
here is my test codes to show you the error
C#:
public partial class Form1 : Form
{
string imgFilePath;
Image memoryIMG;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
imgFilePath = @"f:\Temp\NW\_bak\exclamationIMG.gif"; //this is an gif (animated) image, it throws gdi error
//imgFilePath = @"f:\Temp\NW\_bak\banLangIMG.png"; //this does work fine
}
private void DirectAccessButton_Click(object sender, EventArgs e)
{
//direct access from file just work fine
TestPicturebox.Image = Image.FromFile(imgFilePath);
}
private void LoadToMemoryButton_Click(object sender, EventArgs e)
{
//this proc load the file into memory
using(FileStream imgStream = new FileStream(imgFilePath, FileMode.Open, FileAccess.Read))
{
memoryIMG = Image.FromStream(imgStream);
}
}
private void MemoryAccessButton_Click(object sender, EventArgs e)
{
//this try to show the image from memory and throws error in case of gif but not on png file
TestPicturebox.Image = memoryIMG;
}
private void TestMemoryButton_Click(object sender, EventArgs e)
{
//i tried to save to local file from memory and the image viewer can show the file fine that's means memory is good
string tempPath = Path.GetTempFileName();
memoryIMG.Save(tempPath);
}
}
any idea why is this happening?
thanks in advance
best regards