Exemple #1
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);
        }
Exemple #2
0
        static public IBitmapImage BitmapToIImageBitmap(Bitmap bitmap)
        {
            if (bitmap == null)
            {
                throw new ArgumentNullException();
            }

            ImagingFactory factory = new ImagingFactoryClass();

            System.Drawing.Imaging.BitmapData bd = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            IBitmapImage imageBitmap             = null;

            factory.CreateNewBitmap((uint)bd.Width, (uint)bd.Height, bd.PixelFormat, out imageBitmap);
            BitmapDataInternal bdi = new BitmapDataInternal();
            RECT rc = new RECT(0, 0, bd.Width, bd.Height);

            imageBitmap.LockBits(rc, (int)ImageLockMode.WriteOnly, bd.PixelFormat, ref bdi);
            int cb = bdi.Stride * bdi.Height;

            CopyMemory(bdi.Scan0, bd.Scan0, cb);
            bitmap.UnlockBits(bd);
            imageBitmap.UnlockBits(ref bdi);
            return(imageBitmap);
        }
Exemple #3
0
 /// <summary>
 /// Create a new bitmap image object on user-supplied memory buffer
 /// </summary>
 /// <param name="bitmapData"></param>
 /// <param name="bitmap"></param>
 /// <returns></returns>
 public virtual extern int CreateBitmapFromBuffer(
     ref BitmapDataInternal bitmapData,
     out IBitmapImage bitmap
     );