Example #1
0
        public unsafe void LoadBitmap()
        {
            //Debug.WriteLine( "FileName = " + _strFileName + " ID = " + _iID );
            //Debug.Assert( this.ParentTextures != null );
            Debug.Assert(this.IsBitmapLoaded == false);
            Debug.Assert(this.FileName != null);

            string fileName = Path.Combine(ExoEngine.sTexturePath, Path.GetFileNameWithoutExtension(this.FileName));

            foreach (string extension in ExoEngine.sTextureExtensions)
            {
                fileName = Path.ChangeExtension(fileName, extension);
                if (File.Exists(fileName) == true)
                {
                    break;
                }
            }

            if (File.Exists(fileName) == false)
            {
                throw new FileNotFoundException("'" + this.FileName + "' couldn't be resolved to a file", "this.FileName");
            }

            Bitmap bitmap = new Bitmap(fileName);

            Debug.Assert(bitmap != null);

            _width  = Math2.RoundToBase(bitmap.Width, 2);
            _height = Math2.RoundToBase(bitmap.Height, 2);

            // resize to a power of two if necessary.
            if (_width != bitmap.Width || _height != bitmap.Height)
            {
                bitmap = new Bitmap(bitmap, _width, _height);
            }

            _data = BitmapUtils.ConvertBitmapToRGBAArray(bitmap);
            BitmapUtils.FlipVerticallyRGBAArray(_data);

            // load bitmap data, and flip it

            /*int size = _width * _height;
             * _data = new uint[ size ];
             * Rectangle	rect		= new Rectangle( 0, 0, _width, _height );
             * BitmapData	bitmapdata	= bitmap.LockBits( rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb );
             * uint* pBitmapData = (uint*) bitmapdata.Scan0.ToPointer();
             * for( int i = 0; i < size; i ++ ) {
             *      _data[size - i - 1] = pBitmapData[i];
             * }
             * bitmap.UnlockBits( bitmapdata );*/

            Debug.Assert(this.IsBitmapLoaded == true);
        }