SOS,how to load a invalid or damaged .gif file to create Image Object.

  • Thread starter Thread starter zooots
  • Start date Start date
Z

zooots

hi everyone.
my question is this:how to load a .gif image file that is invalid or damaged
image format?
Notice,I want to load the invalid damaged image file to operate it.
my code is below,but all of they are not correct.
 
zooots said:
hi everyone.
my question is this:how to load a .gif image file that is invalid or damaged
image format?

If the image data is incorrect as far as the Image class knows, you can't.
Notice,I want to load the invalid damaged image file to operate it.
my code is below,but all of they are not correct.

It's possible that the format is in fact correct, but just unsupported
by the Image class. It's also possible that the image loading code in
IE and Picasa is able to ignore errors in images.

It's possible that the WPF image-handling classes have different
features and limitations. It might be worth trying those to load the
bitmap (I don't have the specifics, but I believe it includes similar
functionality to the Image.FromFile() and .FromStream() methods).

Namespace: System.Windows.Media.Imaging
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.aspx

Pete
 
using System.Windows.Media.Imaging;
I try to convert BitmapImage or BitmapSource to Image,
BitmapImage.CopyPixels() throw an IOException "Can not read data from
stream".
what's wrong?
code like this:
------
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.UriSource = new Uri(fileName,
UriKind.RelativeOrAbsolute);
bitmapImage.EndInit();

//FileStream fs = new FileStream(this.strPhotoPath,
FileMode.Open, FileAccess.Read);
//GifBitmapDecoder decoder = new GifBitmapDecoder(new
Uri(this.strPhotoPath), BitmapCreateOptions.PreservePixelFormat,
BitmapCacheOption.OnDemand);
//BitmapSource bitmapImage = decoder.Frames[0];

int width = bitmapImage.PixelWidth;
int height = bitmapImage.PixelHeight;
int stride = width * ((bitmapImage.Format.BitsPerPixel + 7) /
8);

byte[] bits = new byte[height * stride];
//throw an IOException here:"Can not read data from stream"
bitmapImage.CopyPixels(bits, stride, 0);
//fs.Close();

unsafe
{
fixed (byte* pBits = bits)
{
IntPtr ptr = new IntPtr(pBits);
System.Drawing.Bitmap bitmap = new
System.Drawing.Bitmap(width, height, stride, PixelFormat.Format32bppPArgb,
ptr);
return bitmap;
}
}
-------
 
I wonder accurately whether the invalid damaged image file can be load to
create an "Image" object in System.Windows.Media.Imageing.

thanks
 
zooots said:
hi everyone.
my question is this:how to load a .gif image file that is invalid or
damaged image format?
Notice,I want to load the invalid damaged image file to operate it.
my code is below,but all of they are not correct.
Did you try editing it in picasa and saving as jpg?
 
hi,
yes,it can be save as jpg using Picasa,but I just want to edit the damaged
image in c#,not in any other software manually.
do you have any good idea?
thanks
 
zooots said:
hi,
yes,it can be save as jpg using Picasa,but I just want to edit the damaged
image in c#,not in any other software manually.
do you have any good idea?
thanks

My good idea is to fix it before trying to edit it in c#.
 
any other ideas?

zooots said:
hi everyone.
my question is this:how to load a .gif image file that is invalid or
damaged image format?
Notice,I want to load the invalid damaged image file to operate it.
my code is below,but all of they are not correct.
Why not download Irfan View (free) load the image, see if that gives probs.

Zach
 
Back
Top