Пример #1
0
 public static Bitmap IBitmapImageToBitmap(IBitmapImage imageBitmap)
 {
     if (imageBitmap == null)
         throw new ArgumentNullException();
     Size size;
     imageBitmap.GetSize(out size);
     Rectangle rect = new Rectangle(0, 0, size.Width, size.Height);
     BitmapData lockedBitmapData = new BitmapData();
     imageBitmap.LockBits(ref rect, 0U, PixelFormatID.PixelFormat16bppRGB565, out lockedBitmapData);
     Bitmap bitmap = new Bitmap((int)lockedBitmapData.Width, (int)lockedBitmapData.Height,
         PixelFormat.Format16bppRgb565);
     System.Drawing.Imaging.BitmapData bitmapdata = bitmap.LockBits(
         new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly,
         PixelFormat.Format16bppRgb565);
     ImageHelpers.CopyMemory(bitmapdata.Scan0, lockedBitmapData.Scan0, (int)(lockedBitmapData.Height * lockedBitmapData.Stride));
     imageBitmap.UnlockBits(ref lockedBitmapData);
     bitmap.UnlockBits(bitmapdata);
     return bitmap;
 }
Пример #2
0
        unsafe public static Texture LoadBitmap(BitmapLoadData loadData)
        {
            IBitmapImage bitmap        = loadData.Bitmap;
            bool         isTransparent = loadData.IsTransparent;

            Size size;

            bitmap.GetSize(out size);
            RECT rect = new RECT(0, 0, size.Width, size.Height);

            uint glFormat = gl.GL_RGB;
            uint glType   = gl.GL_UNSIGNED_SHORT_5_6_5;

            if (isTransparent)
            {
                glFormat = gl.GL_RGBA;
                glType   = gl.GL_UNSIGNED_BYTE;
            }

            Texture ret = new Texture();

            uint tex;

            gl.GenTextures(1, &tex);
            ret.myName = tex;

            gl.BindTexture(gl.GL_TEXTURE_2D, ret.myName);

            gl.TexImage2D(gl.GL_TEXTURE_2D, 0, glFormat, size.Width, size.Height, 0, glFormat, glType, loadData.Data.Scan0);

            gl.TexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR);
            gl.TexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR);
            gl.TexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE);
            gl.TexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE);

            ret.myWidth         = loadData.Width;
            ret.myHeight        = size.Height;
            ret.myIsTransparent = isTransparent;

            return(ret);
        }
Пример #3
0
        static public Bitmap IBitmapImageToBitmap(IBitmapImage imageBitmap)
        {
            if (imageBitmap == null)
            {
                throw new ArgumentNullException();
            }

            Size szRotated;

            imageBitmap.GetSize(out szRotated);
            RECT rcLock            = new RECT(0, 0, szRotated.Width, szRotated.Height);
            BitmapDataInternal bdi = new BitmapDataInternal();

            imageBitmap.LockBits(rcLock, 0, PixelFormat.Format24bppRgb, ref bdi);
            Bitmap bitmap = new Bitmap(bdi.Width, bdi.Height, bdi.PixelFormat);

            System.Drawing.Imaging.BitmapData bd = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bdi.PixelFormat);
            CopyMemory(bd.Scan0, bdi.Scan0, bdi.Height * bdi.Stride);
            imageBitmap.UnlockBits(ref bdi);
            bitmap.UnlockBits(bd);
            return(bitmap);
        }