Search Unity

Error Unity Web build (System.Runtime.InteropServices.ComTypes.IStream)

Discussion in 'Scripting' started by Shyvazz, Jul 23, 2014.

  1. Shyvazz

    Shyvazz

    Joined:
    Sep 22, 2012
    Posts:
    3
    Hey everyone,

    I'm intern working for municipality as programmer, sow mij knowledge of c# has its limits.
    I have a problem with my Web build. I'm downloading a ".gif" from (http://xml.buienradar.nl/icons/p.gif) witch is provided bij xml document(http://xml.buienradar.nl/) basically there weather icons I can yous for my (UI).
    In the Standalone (Platform) it works as it should with the addition of (System.Drawing & System.Xml.Linq) , but wen I build it for web player the icon does not appear.

    Unity web build with Script Debugging gives log error
    I added "mscorlib" but that dint work.
    I look for solution but dint find one.
    I need someone to point me in the right direction.
    Is it a security problem with web build witch dos not allow me to use this class.
    Is it a problem with the way I `download` the .gif, or that the `steam` method attempted to read past the end of the stream.

    Link to code I used to convert byte´s to a texture, (http://answers.unity3d.com/questions/575942/converting-gif-from-downloaded-byte-array-to-jpeg.html)
    Code (CSharp):
    1. public IEnumerator WeerBerichtIcon()
    2.     {
    3.         string urlIcon = infoXml[6];
    4.         Debug.Log(urlIcon);
    5.         WWW iconwww = new WWW(urlIcon);
    6.         yield return iconwww;
    7.         byte[] ab = iconwww.bytes;
    8.         byte[] pngBytes;
    9.         using (var gifStream = new MemoryStream(ab))
    10.         using (var image = Bitmap.FromStream(gifStream))
    11.         using (var pngStream = new MemoryStream())
    12.         {
    13.             image.Save(pngStream, ImageFormat.Png);
    14.             pngBytes = pngStream.ToArray();
    15.         }
    16.         tex = new Texture2D(Screen.width /2, Screen.height/2, TextureFormat.RGB24, false);
    17.         tex.LoadImage(pngBytes);
    18.         guitexture = tex;
    19.         iconLoaded = true;
    20.     }
    I used openoffice to "auto-correct" hope its readable.
     
  2. Kalekin

    Kalekin

    Joined:
    Apr 20, 2013
    Posts:
    21
    The issue I see here is that the WebPlayer .NET library doesn't include the System.Runtime.InteropServices.ComTypes namespace, which is what the System.Drawing.Bitmap.FromStream class member seems to be trying to use internally. One of the replies in your Unity Answers link confirms that this method unfortunately does not work in the WebPlayer.

    After a bit of searching I couldn't find any examples for loading/converting gifs that didn't fall back onto the System.Drawing classes. Your best bet might be to take a look at something on the asset store, perhaps this. Alternatively you can do some more searching and see if you can't find a .NET library that doesn't work off System.Drawing.
     
  3. Shyvazz

    Shyvazz

    Joined:
    Sep 22, 2012
    Posts:
    3
    System.Drawing class works in Webplayer I use it to draw other textures on my GUI. Haven't had error or problems.
    Also don't need to display it as a .gif on GUI. Just want a (png) from it.
    The WWW class only allows the downloading of (jpg or png) thats wy I wanted to download the .gif as bytes. Later converting it to a png.

    Example
    Stand Alone Version

    Web Build

    The "sun" is the .gif converted to a 2D texture. (GUI.DrawTexture), the compass and the arrow pointing downwards are also drawn on the GUI, they work fine.
    Ill do some more research on .Net library and so on. If i find a solution to my problem ill post it here.
    Ty Kalekin
     
    Last edited: Jul 23, 2014
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Bitmap might be in System.Drawing but FromStream takes an IStream as an argument which is in InteropServices.