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

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.
--------
1.Image.FromFile(fileName);load from a file directly,it throws a 
OutOfMemoryException.In msdn,it's mean the file is a invalid image format.
2.Image.FromStream(stream);load from stream,it throws a ArgumentException.
--------
ps:IE and Google Picasa can load and display the damaged .gif file correct. 


0
zooots
3/11/2010 3:31:26 PM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

10 Replies
1407 Views

Similar Articles

[PageSpeed] 31

Or there is any other methods to operate the invalid image file like 
watermark?

"zooots" <showlie@163.com> д����Ϣ����:eLTst$SwKHA.4908@TK2MSFTNGP06.phx.gbl...
> 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.
> --------
> 1.Image.FromFile(fileName);load from a file directly,it throws a 
> OutOfMemoryException.In msdn,it's mean the file is a invalid image format.
> 2.Image.FromStream(stream);load from stream,it throws a ArgumentException.
> --------
> ps:IE and Google Picasa can load and display the damaged .gif file 
> correct.
> 


0
zooots
3/11/2010 4:27:40 PM
zooots wrote:
> 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.
> --------
> 1.Image.FromFile(fileName);load from a file directly,it throws a 
> OutOfMemoryException.In msdn,it's mean the file is a invalid image format.
> 2.Image.FromStream(stream);load from stream,it throws a ArgumentException.
> --------
> ps:IE and Google Picasa can load and display the damaged .gif file 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
0
Peter
3/11/2010 4:28:04 PM
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;
                }
            }
-------
"Peter Duniho" <no.peted.spam@no.nwlink.spam.com> 
??????:O8knUfTwKHA.732@TK2MSFTNGP06.phx.gbl...
> zooots wrote:
>> 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.
>> --------
>> 1.Image.FromFile(fileName);load from a file directly,it throws a 
>> OutOfMemoryException.In msdn,it's mean the file is a invalid image 
>> format.
>> 2.Image.FromStream(stream);load from stream,it throws a 
>> ArgumentException.
>> --------
>> ps:IE and Google Picasa can load and display the damaged .gif file 
>> 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 


0
zooots
3/11/2010 7:01:57 PM
I wonder accurately whether the invalid damaged image file can be load  to 
create an "Image" object in System.Windows.Media.Imageing.

thanks

"Peter Duniho" <no.peted.spam@no.nwlink.spam.com> 
??????:O8knUfTwKHA.732@TK2MSFTNGP06.phx.gbl...
> zooots wrote:
>> 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.
>> --------
>> 1.Image.FromFile(fileName);load from a file directly,it throws a 
>> OutOfMemoryException.In msdn,it's mean the file is a invalid image 
>> format.
>> 2.Image.FromStream(stream);load from stream,it throws a 
>> ArgumentException.
>> --------
>> ps:IE and Google Picasa can load and display the damaged .gif file 
>> 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 


0
zooots
3/11/2010 7:44:27 PM
Who can help me solve the problem?
thanks a lot!

"zooots" <showlie@163.com> д����Ϣ����:eLTst$SwKHA.4908@TK2MSFTNGP06.phx.gbl...
> 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.
> --------
> 1.Image.FromFile(fileName);load from a file directly,it throws a 
> OutOfMemoryException.In msdn,it's mean the file is a invalid image format.
> 2.Image.FromStream(stream);load from stream,it throws a ArgumentException.
> --------
> ps:IE and Google Picasa can load and display the damaged .gif file 
> correct.
> 


0
zooots
3/12/2010 8:37:38 AM
"zooots" <showlie@163.com> wrote in message 
news:eLTst$SwKHA.4908@TK2MSFTNGP06.phx.gbl...
> 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.
> --------
> 1.Image.FromFile(fileName);load from a file directly,it throws a 
> OutOfMemoryException.In msdn,it's mean the file is a invalid image format.
> 2.Image.FromStream(stream);load from stream,it throws a ArgumentException.
> --------
> ps:IE and Google Picasa can load and display the damaged .gif file 
> correct.
>
Did you try editing it in picasa and saving as jpg? 

0
Andy
3/12/2010 10:34:37 AM
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

"Andy O'Neill" <aon14nocannedmeat@lycos.co.uk> 
??????:2Nomn.310635$yV6.96819@newsfe27.ams2...
>
> "zooots" <showlie@163.com> wrote in message 
> news:eLTst$SwKHA.4908@TK2MSFTNGP06.phx.gbl...
>> 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.
>> --------
>> 1.Image.FromFile(fileName);load from a file directly,it throws a 
>> OutOfMemoryException.In msdn,it's mean the file is a invalid image 
>> format.
>> 2.Image.FromStream(stream);load from stream,it throws a 
>> ArgumentException.
>> --------
>> ps:IE and Google Picasa can load and display the damaged .gif file 
>> correct.
>>
> Did you try editing it in picasa and saving as jpg? 


0
zooots
3/12/2010 11:07:08 AM
"zooots" <showlie@163.com> wrote in message 
news:%238tTrQdwKHA.3408@TK2MSFTNGP06.phx.gbl...
> 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#. 

0
Andy
3/12/2010 12:01:37 PM
any other ideas?

"zooots" <showlie@163.com> д����Ϣ����:eLTst$SwKHA.4908@TK2MSFTNGP06.phx.gbl...
> 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.
> --------
> 1.Image.FromFile(fileName);load from a file directly,it throws a 
> OutOfMemoryException.In msdn,it's mean the file is a invalid image format.
> 2.Image.FromStream(stream);load from stream,it throws a ArgumentException.
> --------
> ps:IE and Google Picasa can load and display the damaged .gif file 
> correct.
> 


0
zooots
3/15/2010 10:52:56 AM
On 15/03/2010 11:52, zooots wrote:
> any other ideas?
>
> "zooots"<showlie@163.com>  д����Ϣ����:eLTst$SwKHA.4908@TK2MSFTNGP06.phx.gbl...
>> 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.
>> --------
>> 1.Image.FromFile(fileName);load from a file directly,it throws a
>> OutOfMemoryException.In msdn,it's mean the file is a invalid image format.
>> 2.Image.FromStream(stream);load from stream,it throws a ArgumentException.
>> --------
>> ps:IE and Google Picasa can load and display the damaged .gif file
>> correct.
>>
>
>
Why not download Irfan View (free) load the image, see if that gives probs.

Zach
0
Zach
3/22/2010 10:53:09 AM
Reply:

Similar Artilces:

CRichEdirCtrl
(cross posted from comp.os.ms-windows.programmer.tools.mfc) I have created a dialog with a CRichEditCtrl. If I drag a file into the window, the cursor changes to one with a plus sign, and when I drop, I get a notification which I can pick up in OnNotify (see below). But how do I actually get the file to be embedded in the control? The functionality I want is that when the user drags in a word doc, or a jpg etc, it should drop the file in as an attachment. But in fact, nothing happens. What haven't I done? BOOL CMyDialog::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { ...

what message I get if new files is updated in the file system
Hi All, I have written my Folder browser functionality. Now I want to know When I add a File/Folder to a perticular directory. but it does not change/Update My Folder Browser. Can you please tell me what message that I need to process to synchronize my folder browser with the File System. Thanks Anup You might be able to use something like what David wrote in this article. This only works on NT based systems (I.E., no Win 98 or ME) http://www.codeproject.com/KB/system/FolderWatch.aspx Tom "Matrixinline" <anup.kataria@gmail.com> wrote in message news:401e3428-37b0-459c-...

Return to the last accessed cell in a multiple paged file at reent
I have an Excel file at work that I did not create, with multible tabs (pages). Hyperlinks from the main page take me to the sub-pages. Some of the sub-pages open to the last accessed cell on that page, some take me to the top of that page. What can I do to make all pages open to the last accessed cell? ...

Newbie question: Loading an XML document into an object
I'm new to XML. I've searched for an answer to this question, but haven't found the right one, so I'm posting here. I've created a class named Order, which contains some data columns (CustName, CustAddr, etc). I also have an XML document which contains an Order's data. Is there a VB command that will automatically place all the XML document's elements into their appropriate place in the Order, i.e place the CustName data from the XML doc into the CustName field of the Order object, etc? Something like the following Dim Order As New Order Order = XmlDoc.Com...

"Invalid use of Null" in query
I have a query which has suddenly started giving this error. It is based on two other queries, each of which run OK. The query contains 4 left joins (I'm wanting to return a complete set of records from the left query), and the left query has no nulls in any field. The SQL of the query is: SELECT qryStaffEffortFYWBSDivPeriod.FY, qryStaffEffortFYWBSDivPeriod.WBS, qryStaffEffortFYWBSDivPeriod.DivID, qryStaffEffortFYWBSDivPeriod.Period, Sum(qryStaffEffortOverhead.Hours) AS TotalHours, Sum(qryStaffEffortOverhead.CostOH) AS TotalCostOH FROM qryStaffEffortFYWBSDivPeriod LEFT JOIN qr...

open already opened file
Hi, I have some VBA-code that opens an Excel-workbook. But when that workbook is already open, I want this action to be aborted and set my workbook variable to the existing opened workbook. Anyone know how to do this? Kind regards, Nico. One way: Dim wb As Workbook On Error Resume Next Set wb = Workbooks("MyBook.xls") On Error GoTo 0 If wb Is Nothing Then _ Set wb = Workbooks.Open ... In article <u8hJTG1gHHA.1244@TK2MSFTNGP04.phx.gbl>, "Nico" <haegens_nico@hotmail.com> wrote: > Hi, > > I have some VBA-code that ...

Excel
Thanks in advance for any assistance. On some machines, when a user opens an Excel file from SharePoint and checks out for edit and -does not- use the local drafts folder, you see a dialog with "File Conversion In Progress", then "Converter Failed To Save File" message, but the file is checked out to the user and will not open in the Excel. A kind-of workaround, is to use local drafts for the Check Out, but if the user tries to launch the file via the link in SharePoint, the "Converter Failed To Save File" message is displayed. Both machines have SP1 and the la...

Duplicate files open from autorecover
Excel has developed an annoying problem that reinstalling/repair hasn't cured. I haven't changed any settings so I'm not sure what is causing the problem. I have files set to autorecover every 10 minutes. Usually when I've got a file open a very small temporary file (*.TMP, several K only in size) is opened while I'm working with it, but these disappear after I close Excel. What is happening instead is that when autorecover occurs, a second file is opened of the exactly same size as the orginal one -- this second file has the name of the file I'm working with and a nume...

Filters *SOS* Filters *SOS* Filters *SOS*
1) On formLoad, I need to show only those items which are unassigned. 2) I need for the end-under to select only the items they are assigned to. 3) I need an option to select "ALL" so I can view all items. Any insight offered would be appreciated!!! On Wed, 29 Aug 2007 16:24:01 -0700, valdaiway <valdaiway@discussions.microsoft.com> wrote: >1) On formLoad, I need to show only those items which are unassigned. Use a query to put a criterion on the field that defines the assigned status. I assume you know how that information is stored in your table; nobody here does, ...

Re: WMV files.
���� ����� "feras" <hotmel71@yahoocom> �� ����� �������:... > ���� �� ���� ������� > > > ...

File Drop, Windows 7 x64
Hello, With VS 2008 on Windows 7 x64, I can't debug a simple file drop on an empty form. No events are fired. If I execute the exe outside VS, it works. Anyone can confirm this ? Is there a way I don't know to debug this ? Thanks. -- Fred foleide@free.fr "Fred" <foleide@free.fr.invalid> a �crit dans le message de groupe de discussion : 7158DDFA-D357-416C-9A92-C6EC52AD7F6B@microsoft.com... > Hello, > > With VS 2008 on Windows 7 x64, I can't debug a simple file drop on an > empty form. > No events are fired. > If I ex...

CListBox::create problem
Hello, My application crashes when calling this method in OnInitDialog() . Could you tell me what is the problem? Here what i do: BOOL CPCM_ViewDlg::OnInitDialog() { [generated code...] // TODO: Add extra initialization here m_DeviceList.Create ( WS_VISIBLE | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP, CRect(7,10,241,168), this, IDC_LIST1 ); } m_DeviceList is a member of CPCM_ViewDlg. Thanking you in advance Are you calling it after the call to base class CDialog::OnInitDialog(); ? It should be something like BOOL YourDi...

EDI File Export
Hi, We would like to utilize the EFT module in GP. Does this moule support generation of EDI files? Our bank has an EDI file format which can be utilized to make multiple types of payments, all in a single file. I looked at the EFT module, and did not see a pre-defined format for EDI - so is this still viable, maybe using the User Defined format option? What other options are available in GP to generate EDI files from the Payables Module? Thanks in Advance, SAndeep. Hi Sandeep, I've worked for several years with EDI and GP, unfortunately Microsoft never though about EDI and how a...

How to bulk-import addressbooks from CSV files to Contacts folders?
Hello, I'm preparing to migrate from a relatively unknown mailsystem to Exchange. To migrate the users' messages, I plan on using the MS Exchange Migration Wizard's IMAP mode. However, my problem is importing the users' addressbooks into their new Exchange mailboxes. I have written a utility to export the users' addressbooks to CSV files. My quesition is if there's a utility similar to the Migration Wizard for bulk-importing addressbooks into users' Contacts folders? There are several thousand users so doing it manually per-user is no feasible. I'd need to ...

trying to "paste special" data; why does worksheet object appear?
Hello, My problem is that I will select data in one sheet or workbook, copy it, then select "paste special" to paste with a specific format (e.g. keep column widths, values only etc.) into a new sheet; when I try to "paste special" into the new sheet, the data is somehow read as a Worksheet Object, and my choices are Picture, Bitmap etc. How can I fix this? Thanks very much in advance for your advice. Alyssa It sounds like you have two instances of excel open and are trying to paste between them. If you close one instance and then use File|open to open the other ...

Can Only open files using file ~ open
Workstation running W2K sp4, O2K, Excel ver 9.0 build 2719. I must open excel first and then use file open on this particular workstation, the same files open fine on other workstations fine. Location does not seem to matter, network files vs local. Renaming files did nothing as well, Uninstalled the Office Suite and Reinstalled - Same Pblm. If I open my documents and attempt to open an excel file I get the following. A window opens showing Excel with the tool bar being visable but were my sheet data should be is being replaced with a screen shot of the current desktop. Thx in advance ~ te...

program loading time
The money 05 loads very slow, I have archived everthing past 90 days but it still loads slow. Any suggestions? In microsoft.public.money, oltexasboy wrote: >The money 05 loads very slow, I have archived everthing past 90 days but it >still loads slow. Any suggestions? Restore the archive as your main file, if you have not gone too far with it since the archive. Archiving did not help your speed appreciably, and you might want to refer to that older data. Consider reducing scheduled bills. Remove accounts from the budget if you think that would be appropriate. Set your start page t...

Excel Doesn't Load Properly
Would greatly appreciate any help sources to resolve the following. Many thanks in advance. Excel 2000 Problem Occurred 9/21/2004 (Using Win 98SE) Started up Excel (part of MS Office 2000 Small Business Edition). Following occurred: Error msg received: �An error occurred and this feature is no longer functioning properly. Would you like to repair this featured now?� Yes No Clicked on Yes ; following error msg appears: VBA (3821h) Internal Error 2709. (EEE4D698-20C7-11D2-A185-00A0C90AB50F) OK Clicked on OK; following msg appeared: �Microsoft Excel cannot install the neces...

Can Picture Manager change an image background to transparent?
I made an image in Publisher, but cannot reopen it unless I use Picture Manager, so I was wondering if it is possible, in either program (I will remake the picture if need be) to change the background to transparent? It is going up on a website and I cannot color match due to a fading affect. Download www.irfanview.com with the plug-ins. You will be able to open an image and convert it to .png or .gif so the background can be made transparent. The program is free. -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Corki"...

oeaccount file
XP Pro SP3 With "Show hidden files and folders" selected in Folder options>View: C://Documents and Settings/Username/Local Settings/Application Data/Software/Microsoft/Windows Live Mail Responding to a request from Windows Live Solution Centre, I was asked to see if I could open and edit an oeaccount file in the above folder. e.g. account{1234-1234-1234-1234}oeaccount Right clicked and selected Open. Was told that "Windows cannot open this file". I selected Notepad. The "Always use this program to open this type of file" option was ticked...

Reading old files with excel or word 2000
I have several old MSMultiplanfiles and want to read them with word or excel2000. How can I do this.-- geometeocalpe Whilst I have no experience with Multiplan, the Wikipedia entry suggest that your file would be something like text format, so you could try vi Data, Import External Data, Import Data, locate the file, and set th delimiters to suit your data. -- geoexcel Wrote: > I have several old MSMultiplanfiles and want to read them with word or > excel2000. How can I do this.-- > geometeocalp -- Bryan Hesse --------------------------------------------------------------------...

how do I open older version of file
accidentally replaced file can I retrieve an older version Do you have a backup somewhere? sharon wrote: > > accidentally replaced file can I retrieve an older version -- Dave Peterson yes but is 5 months old so not much on it have been told that can buy software to retreive files as they are still on the computer just in background ie police can retreive deleted files any ideas "Dave Peterson" wrote: > Do you have a backup somewhere? > > sharon wrote: > > > > accidentally replaced file can I retrieve an older version > > -- > > ...

Saving a pub file to PDF
Am using the 2007 beta office 2. After the technical refresh, I could no longer save my file in a PDF format. Did download the pdf add in from microsoft but now publisher says it cannot save the file. Anybody else with this problem and do you have a work around? Thanks That's because the current add-in was designed for the released version, not the beta. -- JoAnn Paules MVP Microsoft [Publisher] ~~~~~ How to ask a question http://support.microsoft.com/KB/555375 "billb" <billb@discussions.microsoft.com> wrote in message news:F3D8CBFB-C3FB-403B-BDBF-72A0D9AB710B...

Easy way to see hex-ascii dump of file?
Is there an easy way to see a hex-and-ascii dump of file? I can write a VBA macro to read and format the data myself. But it would be so much easier (of course) if there already exists a (DOS?) command to do this, like an option to TYPE or MORE. (None that I see with HELP.) I am somewhat adept at using VBA in Excel. Is there a feature of that VBA that I can exploit, short of rolling my own? I am using Win XP SP3. PS: I discovered that I can use the DOS command DEBUG, viz.: `debug myfile >myout`, followed by the DEBUG "d" and "q" commands. Tha...

Cannot load Money 2003
Every time I try installing Money, I get window that shows the program did not install and click finsh to exit. I cannot get setup to run. Try some of the suggestions in the following article: http://support.microsoft.com/default.aspx?scid=kb;en-us;827814&Product=mny "Starfury9" <anonymous@discussions.microsoft.com> wrote in message news:0f2201c46ed8$72448160$a401280a@phx.gbl... > Every time I try installing Money, I get window that > shows the program did not install and click finsh to > exit. I cannot get setup to run. ...