Ejemplo n.º 1
0
        /// <summary>
        /// Creates a ScaledBitmap from the given original bitmap and replace it's transparent pixels with the
        /// given new color.
        /// </summary>
        /// <param name="originalBmp">The original bitmap.</param>
        /// <param name="transparentColor">The selected transparent color on the original bitmap.</param>
        /// <param name="replaceTo">
        /// The transparent pixels on the original bitmap will be replaced with this color.
        /// </param>
        /// <returns>The created ScaledBitmap.</returns>
        /// <remarks>Disposing originalBmp is the responsibility of the caller.</remarks>
        public static ScaledBitmap FromBitmap(Bitmap originalBmp, Color transparentColor, Color replaceTo)
        {
            if (null == originalBmp)
            {
                throw new ArgumentNullException("originalBmp");
            }
            if (PixelFormat.Format24bppRgb != originalBmp.PixelFormat)
            {
                throw new ArgumentException("Pixel format of the given Bitmap must be PixelFormat.Format24bppRgb",
                                            "originalBmp");
                /// TODO: implement other pixel format support (?)
            }

            ScaledBitmap original     = ScaledBitmap.FromBitmap(originalBmp);
            ScaledBitmap retBmp       = new ScaledBitmap(original.Width, original.Height);
            BitmapAccess retBmpAccess = BitmapAccess.FromBitmap(retBmp);

            retBmpAccess.Clear(replaceTo);
            original.MakeTransparent(transparentColor);
            retBmpAccess.DrawBitmap(original, 0, 0);
            retBmpAccess.Dispose();
            original.Dispose();

            return(retBmp);
        }
Ejemplo n.º 2
0
        /// <see cref="IDrawTarget.DrawBitmap"/>
        public void DrawBitmap(ScaledBitmap src, int x, int y)
        {
            if (null == src)
            {
                throw new ArgumentNullException("src");
            }

            this.graphicContext.DrawImageUnscaled(src.RawBitmap, x * Display.HorizontalScale, y * Display.VerticalScale);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a BitmapAccess object for the given ScaledBitmap.
        /// </summary>
        /// <param name="bmp">The ScaledBitmap object for which you want to create a draw interface.</param>
        /// <returns>The created BitmapAccess object.</returns>
        public static BitmapAccess FromBitmap(ScaledBitmap bmp)
        {
            if (null == bmp)
            {
                throw new ArgumentNullException("bmp");
            }

            return(FromBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height)));
        }
Ejemplo n.º 4
0
        /// <see cref="IDrawTarget.DrawBitmap"/>
        public void DrawBitmap(ScaledBitmap src, int x, int y)
        {
            if (!this.drawAccessGranted)
            {
                throw new RenderSystemException("Access denied on IDrawTarget");
            }

            this.frameBufferAccess.DrawBitmap(src, x + this.targetVP.X, y + this.targetVP.Y);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Constructs a BitmapAccess object for the given ScaledBitmap with the given clipping rectangle.
 /// </summary>
 /// <param name="bmp">The ScaledBitmap object for which you want to create a draw interface</param>
 /// <param name="clipRect">
 /// The clipping rectangle of the draw interface (in logical pixels).
 /// </param>
 private BitmapAccess(ScaledBitmap bmp, Rectangle clipRect)
 {
     this.graphicContext      = Graphics.FromImage(bmp.RawBitmap);
     this.clipBounds          = new Rectangle(clipRect.X, clipRect.Y, clipRect.Width, clipRect.Height);
     this.graphicContext.Clip = new Region(new Rectangle(clipRect.X * Display.HorizontalScale,
                                                         clipRect.Y * Display.VerticalScale,
                                                         clipRect.Width * Display.HorizontalScale,
                                                         clipRect.Height * Display.VerticalScale));
     this.accessedBitmap = bmp;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates a BitmapAccess object for the given ScaledBitmap with the given clipping rectangle.
 /// </summary>
 /// <param name="bmp">The ScaledBitmap object for which you want to create a draw interface</param>
 /// <param name="clipRect">
 /// The clipping rectangle of the draw interface (in logical pixels).
 /// </param>
 /// <returns>The created BitmapAccess object.</returns>
 public static BitmapAccess FromBitmap(ScaledBitmap bmp, Rectangle clipRect)
 {
     if (null == bmp)
     {
         throw new ArgumentNullException("bmp");
     }
     if (null == clipRect)
     {
         throw new ArgumentNullException("clipRect");
     }
     return(new BitmapAccess(bmp, clipRect));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a ScaledBitmap from the given original Bitmap.
        /// </summary>
        /// <param name="originalBmp">The original Bitmap.</param>
        /// <returns>The created ScaledBitmap.</returns>
        /// <remarks>Disposing originalBmp is the responsibility of the caller.</remarks>
        public static ScaledBitmap FromBitmap(Bitmap originalBmp)
        {
            if (null == originalBmp)
            {
                throw new ArgumentNullException("originalBmp");
            }
            if (PixelFormat.Format24bppRgb != originalBmp.PixelFormat)
            {
                throw new ArgumentException("Pixel format of the given Bitmap must be PixelFormat.Format24bppRgb",
                                            "originalBmp");
                /// TODO: implement other pixel format support (?)
            }
            ScaledBitmap retBmp = new ScaledBitmap(originalBmp.Width, originalBmp.Height);

            CopyBitmapScaled(originalBmp, retBmp.rawBitmap);
            return(retBmp);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a ScaledBitmap from the given original bitmap and replace it's transparent pixels with the
        /// pixels of another bitmap.
        /// </summary>
        /// <param name="originalBmp">The original bitmap.</param>
        /// <param name="transparentColor">The selected transparent color on the original bitmap.</param>
        /// <param name="replaceTo">
        /// The transparent pixels on the original bitmap will be replaced with the pixels of this bitmap.
        /// </param>
        /// <returns>The created ScaledBitmap.</returns>
        /// <remarks>Disposing originalBmp and replaceTo is the responsibility of the caller.</remarks>
        public static ScaledBitmap FromBitmap(Bitmap originalBmp, Color transparentColor, Bitmap replaceTo)
        {
            if (null == originalBmp)
            {
                throw new ArgumentNullException("originalBmp");
            }
            if (null == replaceTo)
            {
                throw new ArgumentNullException("replaceTo");
            }
            if (PixelFormat.Format24bppRgb != originalBmp.PixelFormat || PixelFormat.Format24bppRgb != replaceTo.PixelFormat)
            {
                throw new ArgumentException("Pixel format of the given Bitmaps must be PixelFormat.Format24bppRgb");
                /// TODO: implement other pixel format support (?)
            }

            ScaledBitmap original     = ScaledBitmap.FromBitmap(originalBmp);
            ScaledBitmap replaceToBmp = ScaledBitmap.FromBitmap(replaceTo);

            ScaledBitmap retBmp       = new ScaledBitmap(original.Width, original.Height);
            BitmapAccess retBmpAccess = BitmapAccess.FromBitmap(retBmp);

            for (int currX = 0; currX < retBmp.Width; currX = currX + replaceTo.Width)
            {
                for (int currY = 0; currY < retBmp.Height; currY = currY + replaceTo.Height)
                {
                    retBmpAccess.DrawBitmap(replaceToBmp, currX, currY);
                }
            }
            original.MakeTransparent(transparentColor);
            retBmpAccess.DrawBitmap(original, 0, 0);
            retBmpAccess.Dispose();
            original.Dispose();
            replaceToBmp.Dispose();

            return(retBmp);
        }