gdi+ - Problem converting .ico in byte array to Image object in .net -


I am trying to take favicon and am trying to add them to a dynamic image that I am making. See . The website code works fine locally, and on a shared hosting server. Blah blah, free hosting plan, whatever you pay, blah blah My problem is that I get an exception from a new hosting setup This exception is only for .ico files . I have tested .gif and .png images only on all the servers that I have tested (i.e., a gravatar image). The favicons I'm trying to use are favicons from SE networks, but also result in the following exceptions.

System.ArgumentException: The parameter is not valid.

  • The system. Drawing Image Forms (stream stream, boolean usage embedded collar management, boolean valid image data)
  • System Drawing Image The stream (stream stream)

I'm trying to get the variations of the code below that I do not find the same parameter exceptionally valid for all the changes.

byte [] imageBytes => SQL Server / or byte [] from image field] imageBytes = new webclient (). (Image URL); Memorystream ms = new memorystream (imageboys); Image image = image.formstream (ms); // or icon icon = new icon (ms); Image image = icon. ToMit (); // or image image = new bitmap (ms);

All of these work is just fine at the local level and the bad hosting server. None of them work on the server, I want to work on it. Using trace output, I can verify that the length of the array is the correct number of bytes. If I do the following, then the image I expected is displayed.

  response. Clear (); Response.BinaryWrite (imageBytes); Response.End ();  

If I write the loop through the array and each byte value, the output is similar to the server on my local example, where I get the exception.

If it helps, the server where my code does not work with Windows Server 2003 SP2.

Obviously the structure tells me that the stream of bytes is not valid, but whoever investigated I check it. Why are these particular servers chasing on .ICO files, any thoughts on this?

I have an alternative solution to convert ICO files to PNG files using ImageMagic:

  convert favicon.ico [0] favicon.png  

ImageMagick is pre-installed on many shared hosts, or you can download precompiled binaries for Windows.

If you skip [0], then you have to run the Favon-0ppg A series of favicons will be found -1.png etc. If there is more than one icon image stored in the .ICO file. After that you will need to choose who you like most: 16x16 with alpha transparency (I include 32x32 and 48x48 in my favicon files, for IE users, who have internet on their desktop Draws shortcuts.) Image protects transparency while converting Magic Pendi.

Stack-up / Favicon. ICI Gear Icon Two images are the first alpha transparency, and your light brown color # DBDCDDB looks good on the background.

I think that you are creating a dynamic image like you on the server rather than sending all 6 top site icons on the browser. If not, it is still a good idea to send a punch to the png, because they were not designed to render in web pages.

... Tom


Comments