Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
        }