Jump to content
  • Advertisement
Sign in to follow this  
xmen

set image in picturebox in C#

This topic is 4032 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi there, i want to read a binary file that have custom file format file format is : Char(4) = "RTS3" Byte() = usage (some function) Byte() = alpha (unused) Byte() = format (define the pixel format ie. BGRA=1,DXT1=4,GREY=7,DXT3=8,DXT5=9) Byte() = levels (num of pictures, always one) Int32() = width Int32() = height Int32() = offset Int32() = length rest is in byte[] the file data(in any pixel format that define above) to set the image on picturebox with BGRA pixel format i did the coding like this: FileStream fs = new FileStream(@"C:\swizzleXY.ddt", FileMode.Open); BinaryReader br = new BinaryReader(fs); string chk = new string(br.ReadChars(4)); usage = (Type_Usage)br.ReadByte(); // enum defined any where alpha = (Type_Alpha)br.ReadByte(); // enum defined any where format = (Type_Format)br.ReadByte(); // enum defined any where int levels = br.ReadByte(); int width = br.ReadInt32(); int height = br.ReadInt32(); int offset = br.ReadInt32(); int length = br.ReadInt32(); int numImagesPerLevel = 0; if (usage == (Type_Usage)8) numImagesPerLevel = 6; else numImagesPerLevel = 1; int numImages = levels * numImagesPerLevel; int width1 = 0; int height1 = 0; for (int i = 0; i < numImages; i++) { width1 = width >> (i / numImagesPerLevel); if (width1 < 1) width1 = 1; height1 = height >> (i / numImagesPerLevel); if (height1 < 1) height1 = 1; } byte[] byt = new byte[0]; switch (format) { case Type_Format.BGRA: { byte[] dirtybyt = new byte[width1 * height1 * 4]; br.Read(dirtybyt, 0, width1 * height1 * 4); byte[] temp = new byte[width1 * height1 * 4]; for (int i = 0; i < width1 * height1; i++) { temp[i * 4 + 0] = dirtybyt[i * 4 + 3]; //A temp[i * 4 + 1] = dirtybyt[i * 4 + 2]; //R temp[i * 4 + 2] = dirtybyt[i * 4 + 1]; //G temp[i * 4 + 3] = dirtybyt[i * 4 + 0]; //B, convert BGRA to ARGB as we need to open it in picturebox } byt = temp; // ************ } break; } fs.Close(); Bitmap bmp = new Bitmap(width, height); BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); Marshal.Copy(byt, 0, bmpData.Scan0, byt.Length); bmp.UnlockBits(bmpData); pictureBox1.Size = new System.Drawing.Size(width, height); pictureBox1.BackgroundImage = bmp; when i click on the button its show nothing but when i replace the line "byt = temp;" with "byt = dirtybyt;" then it just show half original picture(the line with STARS) Screenshots http://img297.imageshack.us/img297/2398/oritm2.jpg ^^ORIGINAL http://img73.imageshack.us/img73/4954/halfou7.jpg ^^The image after replacing line can some tell how can i solve it? [Edited by - xmen on October 3, 2007 10:24:33 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!