Ejemplo n.º 1
0
        /// <summary>
        /// Converts the BLP to a System.Drawing.Bitmap
        /// </summary>
        /// <param name="mipmapLevel">The desired Mipmap-Level. If the given level is invalid, the smallest available level is choosen</param>
        /// <returns>The Bitmap</returns>
        public Bitmap GetBitmap(int mipmapLevel)
        {
            if (mipmapLevel >= MipMapCount)
            {
                mipmapLevel = MipMapCount - 1;
            }
            if (mipmapLevel < 0)
            {
                mipmapLevel = 0;
            }

            int    scale = (int)Math.Pow(2, mipmapLevel);
            int    w     = width / scale;
            int    h     = height / scale;
            Bitmap bmp   = new Bitmap(w, h);

            byte[] data = GetPictureData(mipmapLevel);
            byte[] pic  = GetImageBytes(w, h, data); // This bytearray stores the Pixel-Data

            // Faster bitmap Data copy
            BitmapData bmpdata = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);

            // when we want to copy the pixeldata directly into the bitmap, we have to convert them into BGRA befor doing so
            ARGBColor8.convertToBGRA(pic);
            Marshal.Copy(pic, 0, bmpdata.Scan0, pic.Length); // copy! :D
            bmp.UnlockBits(bmpdata);

            return(bmp);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns array of pixels in BGRA or RGBA order
        /// </summary>
        /// <param name="mipmapLevel"></param>
        /// <returns></returns>
        public byte[] GetPixels(int mipmapLevel, out int w, out int h, bool bgra = true)
        {
            if (mipmapLevel >= MipMapCount)
            {
                mipmapLevel = MipMapCount - 1;
            }
            if (mipmapLevel < 0)
            {
                mipmapLevel = 0;
            }

            int scale = (int)Math.Pow(2, mipmapLevel);

            w = width / scale;
            h = height / scale;

            byte[] data = GetPictureData(mipmapLevel);
            byte[] pic  = GetImageBytes(w, h, data); // This bytearray stores the Pixel-Data

            if (bgra)
            {
                // when we want to copy the pixeldata directly into the bitmap, we have to convert them into BGRA before doing so
                ARGBColor8.ConvertToBGRA(pic);
            }

            return(pic);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts the BLP to a System.Drawing.Bitmap
        /// </summary>
        /// <param name="MipmapLevel">The desired Mipmap-Level. If the given level is invalid, the smallest available level is choosen</param>
        /// <returns>The Bitmap</returns>
        public Bitmap getBitmap(int MipmapLevel)
        {
            int    x = (this.width / (int)(Math.Pow(2, MipmapLevel))), y = (this.height / (int)(Math.Pow(2, MipmapLevel)));
            Bitmap bmp = new Bitmap(x, y);

            byte[] pic = getImageBytes(MipmapLevel); // This bytearray stores the Pixel-Data

            // Faster bitmap Data copy
            System.Drawing.Imaging.BitmapData bmpdata = bmp.LockBits(new Rectangle(0, 0, x, y), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            // when we want to copy the pixeldata directly into the bitmap, we have to convert them into BGRA befor doing so
            ARGBColor8.convertToBGRA(ref pic);
            System.Runtime.InteropServices.Marshal.Copy(pic, 0, bmpdata.Scan0, pic.Length); // copy! :D
            bmp.UnlockBits(bmpdata);

            /*
             * // Pushing everything into the Bitmap
             * // This technique is realy slow and should not be used
             * for (int y = 0; y < this.height; y++)
             * {
             *  for (int x = 0; x < this.width; x++)
             *  {
             *      int r, g, b, a;
             *      r = pic[(y * this.width + x) * 4 + 0];
             *      g = pic[(y * this.width + x) * 4 + 1];
             *      b = pic[(y * this.width + x) * 4 + 2];
             *      a = pic[(y * this.width + x) * 4 + 3];
             *      Color col = Color.FromArgb(a, r, g, b);
             *      bmp.SetPixel(x, y, col);
             *  }
             * }
             */

            return(bmp);
        }