Search Unity

Image to material texture problems.

Discussion in 'General Graphics' started by Abyss000, Jan 19, 2015.

  1. Abyss000

    Abyss000

    Joined:
    May 12, 2013
    Posts:
    10
    Hi all.

    I am trying to create a Texture2D from a System.Drawing.Bitmap object but I am only seeing a short line of the image in my test plane. Do anyone know how to fix that?

    Here is the piece of code:
    Code (CSharp):
    1. Bitmap b;
    2.                     using (var ms = new MemoryStream(realData))
    3.                     {
    4.                         b = new Bitmap(ms);
    5.                     }
    6.  
    7.                     int w = 960;
    8.                     int h = 540;
    9.                     Texture2D texture = new Texture2D(w, h, TextureFormat.BGRA32, false);
    10.                  
    11.                     byte[] data = new byte[w * h * 4];
    12.                     int pixel = 0;
    13.                     for (int y = 0; y < h; y++) {
    14.                         for (int x = 0; x < w; x++) {
    15.                             System.Drawing.Color c = b.GetPixel(x, y);
    16.                          
    17.                             data[pixel] = c.R;
    18.                             data[pixel+1] = c.G;
    19.                             data[pixel+2] = c.B;
    20.                             data[pixel+3] = c.A;
    21.                             pixel += 4;
    22.                         }
    23.                     }
    This is what I see:
    http://s9.postimg.org/udzm0ljvh/example.png

    Any ideas?

    P.D.: In fact the image is rotated somehow. I mean... the part seen in the bottom of the plane, is actually the top of the image rotated like 180º.
     
    Last edited: Jan 19, 2015