How can i to save byte array data to a stream and convert them to a bitmap instance

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yang from china
    New Member
    • Feb 2008
    • 5

    How can i to save byte array data to a stream and convert them to a bitmap instance

    I cannot open TGA file use framework's class,so I am trying to convert TGA file to BMP file(or others).Now I have read the palette data and pixel data successfully.On e way I create a temporary BMP file so I can open it again by use filestream.but it is stupid.

    Can anyone tell me create bitmap instance by using palette data and pixel data?

    any reply is very thanksful.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Hmm, I'm not sure about creating a bmp from a pallette, but I seem to remember finding the MemoryStream object very usefull in creating bitmaps from byte data. About all I can offer though.

    Comment

    • yang from china
      New Member
      • Feb 2008
      • 5

      #3
      Originally posted by Plater
      Hmm, I'm not sure about creating a bmp from a pallette, but I seem to remember finding the MemoryStream object very usefull in creating bitmaps from byte data. About all I can offer though.
      very thanks for your guide!

      well, I am failed to use MemmoryStream to create bitmap.
      bitmap constructor:bit map(stream);

      When I use MemoryStream to create bitmap,The error window tell me parameter is wrong.so I have to find a way to create bitmap by using palette data and pixel data I get from the TGA file.

      by the way,can you show me how to use MemoryStream to create bitmap?

      thanks!

      Comment

      • yang from china
        New Member
        • Feb 2008
        • 5

        #4
        Originally posted by Plater
        Hmm, I'm not sure about creating a bmp from a pallette, but I seem to remember finding the MemoryStream object very usefull in creating bitmaps from byte data. About all I can offer though.
        Thank you for your reply.I found a way to solve my proble.Can you show me some advices:

        byte[] paletteArr = readPaletteData ();
        byte[] pixelArr = readPixelData() ;

        Bitmap bmp = new Bitmap(Width,He ight);

        for (int i = 0; i < Height;i++ )
        {
        for (int j = 0; j < Width; j++)
        {
        Color tmp;
        int R = (int)paletteArr[pixelArr[i * Width + j] * 3 + 2];
        int G = (int)paletteArr[pixelArr[i * Width + j] * 3 + 1];
        int B = (int)paletteArr[pixelArr[i * Width + j] * 3 + 0];

        tmp = Color.FromArgb( R,G,B);

        bmp.SetPixel(j, Height - 1 - i, tmp);
        }

        }
        return bmp;

        Thanks!

        Comment

        Working...