internal D2dBitmapBrush(D2dGraphics owner, D2dBitmap bitmap)
            : base(owner)
        {
            m_bitmap = bitmap;

            m_extendModeX       = D2dExtendMode.Clamp;
            m_extendModeY       = D2dExtendMode.Clamp;
            m_location          = new PointF(1, 1);
            m_interpolationMode = D2dBitmapInterpolationMode.Linear;
            Create();//to-do: it's dangerous to call a virtual method in a constructor; derived class may not be properly initialized!
        }
Example #2
0
 /// <summary>
 /// Draws a solid rectangle with the specified brush while using the alpha channel of the given
 /// bitmap to control the opacity of each pixel.</summary>
 /// <param name="opacityMask">The opacity mask to apply to the brush. The alpha value of
 /// each pixel in the region specified by sourceRectangle is multiplied with the alpha value
 /// of the brush after the brush has been mapped to the area defined by destinationRectangle.</param>
 /// <param name="color">The color used to paint the region of the render target specified by destinationRectangle.</param>
 /// <param name="destRect">The region of the render target to paint, in device-independent pixels.</param>
 /// <param name="sourceRect">The region of the bitmap to use as the opacity mask, in device-independent pixels.</param>
 public void FillOpacityMask(D2dBitmap opacityMask, Color color, RectangleF destRect, RectangleF sourceRect)
 {
     m_solidColorBrush.Color = color;
     FillOpacityMask(opacityMask, m_solidColorBrush, destRect, sourceRect);
 }
Example #3
0
 /// <summary>
 /// Draws a solid rectangle with the specified brush while using the alpha channel of the given
 /// bitmap to control the opacity of each pixel.</summary>
 /// <param name="opacityMask">The opacity mask to apply to the brush. The alpha value of
 /// each pixel in the region specified by sourceRectangle is multiplied with the alpha value
 /// of the brush after the brush has been mapped to the area defined by destinationRectangle.</param>
 /// <param name="brush">The brush used to paint the region of the render target specified by destinationRectangle.</param>
 /// <param name="destRect">The region of the render target to paint, in device-independent pixels.</param>
 /// <param name="sourceRect">The region of the bitmap to use as the opacity mask, in device-independent pixels.</param>
 public void FillOpacityMask(D2dBitmap opacityMask, D2dBrush brush, RectangleF destRect, RectangleF sourceRect)
 {
     m_renderTarget.FillOpacityMask(opacityMask.NativeBitmap, brush.NativeBrush,
                                    OpacityMaskContent.Graphics,
                                    destRect.ToSharpDX(), sourceRect.ToSharpDX());
 }
Example #4
0
 /// <summary>
 /// Draws the specified bitmap after scaling it to the size of the specified rectangle</summary>
 /// <param name="bmp">The bitmap to render</param>
 /// <param name="destRect">The size and position, in pixels, in the D2dGraphics's coordinate
 /// space, of the area in which the bitmap is drawn. If the rectangle is not well-ordered,
 /// nothing is drawn, but the D2dGraphics does not enter an error state.</param>
 /// <param name="opacity">A value between 0.0f and 1.0f, inclusive, that specifies an opacity value        
 /// to apply to the bitmap. This value is multiplied against the alpha values
 /// of the bitmap's contents.</param>
 /// <param name="interpolationMode">The interpolation mode to use if the bitmap is scaled or rotated 
 /// by the drawing operation</param>
 /// <param name="sourceRect">The size and position, in pixels in the bitmap's coordinate space, of the area
 /// within the bitmap to draw</param>
 public void DrawBitmap(D2dBitmap bmp, RectangleF destRect, float opacity,
     D2dBitmapInterpolationMode interpolationMode, RectangleF sourceRect)
 {
     m_renderTarget.DrawBitmap(bmp.NativeBitmap, destRect.ToSharpDX(), opacity,
         (BitmapInterpolationMode)interpolationMode, sourceRect.ToSharpDX());
 }
Example #5
0
 /// <summary>
 /// Draws the specified bitmap after scaling it to the size of the specifiedrectangle</summary>
 /// <param name="bmp">The bitmap to render</param>
 /// <param name="destRect">The size and position, in pixels, in the D2dGraphics's coordinate
 /// space, of the area in which the bitmap is drawn. If the rectangle is not well-ordered,
 /// nothing is drawn, but the D2dGraphics does not enter an error state.</param>
 /// <param name="opacity">A value between 0.0f and 1.0f, inclusive, that specifies an opacity value        
 /// to apply to the bitmap. This value is multiplied against the alpha values
 /// of the bitmap's contents.</param>
 /// <param name="interpolationMode">The interpolation mode to use if the bitmap is scaled or rotated 
 /// by the drawing operation</param>
 public void DrawBitmap(D2dBitmap bmp, RectangleF destRect, float opacity = 1.0f, D2dBitmapInterpolationMode interpolationMode = D2dBitmapInterpolationMode.Linear)
 {
     m_renderTarget.DrawBitmap(bmp.NativeBitmap, destRect.ToSharpDX(), opacity, (BitmapInterpolationMode)interpolationMode, null);
 }
Example #6
0
 /// <summary>
 /// Draws the specified bitmap at a specified point using the
 /// D2dGraphic's DPI instead of the bitmap's DPI</summary>
 /// <param name="bmp">The bitmap to render</param>
 /// <param name="point">Point structure that represents the location of the upper-left
 /// corner of the drawn bitmap</param>
 /// <param name="opacity">A value between 0.0f and 1.0f, inclusive, that specifies an opacity value
 /// to apply to the bitmap. This value is multiplied against the alpha values
 /// of the bitmap's contents.</param>
 public void DrawBitmap(D2dBitmap bmp, PointF point, float opacity = 1.0f)
 {
     SizeF bmpsize = bmp.PixelSize;
     var rect = new SharpDX.RectangleF(point.X, point.Y, bmpsize.Width, bmpsize.Height);
     m_renderTarget.DrawBitmap(bmp.NativeBitmap, rect, opacity, BitmapInterpolationMode.Linear, null);
 }
Example #7
0
 /// <summary>
 /// Creates an empty Direct2D Bitmap from specified width and height
 /// Pixel format is set to 32 bit ARGB with premultiplied alpha</summary>      
 /// <param name="width">Width of the bitmap in pixels</param>
 /// <param name="height">Height of the bitmap in pixels</param>
 /// <param name="createBackupBitmap">If true a GDI bitmap is created and used
 /// to recreate this D2dBitmap when needed</param>
 /// <returns>A new D2dBitmap</returns>
 public D2dBitmap CreateBitmap(int width, int height, bool createBackupBitmap = true)
 {
     if (width < 1 || height < 1)
         throw new ArgumentOutOfRangeException("Width and height must be greater than zero");
     D2dBitmap  d2dBmp = null;
     if(createBackupBitmap)
     {
         System.Drawing.Bitmap gdiBmp = new System.Drawing.Bitmap(width, height, GdiPixelFormat.Format32bppPArgb);
         d2dBmp = new D2dBitmap(this, gdiBmp);
     }
     else
     {
         d2dBmp = new D2dBitmap(this,width,height);
     }
     return d2dBmp;
 }
Example #8
0
 /// <summary>
 /// Creates a new D2dBitmapBrush from the specified bitmap</summary>
 /// <param name="bitmap">The bitmap contents of the new brush</param>
 /// <returns>A new instance of D2dBitmapBrush</returns>
 public D2dBitmapBrush CreateBitmapBrush(D2dBitmap bitmap)
 {
     return new D2dBitmapBrush(this, bitmap);
 }
Example #9
0
        /// <summary>
        /// Draws a solid rectangle with the specified brush while using the alpha channel of the given
        /// bitmap to control the opacity of each pixel.</summary>
        /// <param name="opacityMask">The opacity mask to apply to the brush. The alpha value of
        /// each pixel in the region specified by sourceRectangle is multiplied with the alpha value
        /// of the brush after the brush has been mapped to the area defined by destinationRectangle.</param>
        /// <param name="brush">The brush used to paint the region of the render target specified by destinationRectangle.</param>
        /// <param name="destRect">The region of the render target to paint, in device-independent pixels.</param>
        /// <param name="sourceRect">The region of the bitmap to use as the opacity mask, in device-independent pixels.</param>
        public void FillOpacityMask(D2dBitmap opacityMask, D2dBrush brush, RectangleF destRect, RectangleF sourceRect)
        {
            var drect = new SharpDX.RectangleF(destRect.X, destRect.Y, destRect.Right, destRect.Bottom);
            var srect = new SharpDX.RectangleF(sourceRect.X, sourceRect.Y, sourceRect.Right, sourceRect.Bottom);

            m_renderTarget.FillOpacityMask(opacityMask.NativeBitmap, brush.NativeBrush,
                                           OpacityMaskContent.Graphics,
                                           drect, srect);
        }
Example #10
0
        /// <summary>
        /// Draws the specified bitmap after scaling it to the size of the specified rectangle</summary>
        /// <param name="bmp">The bitmap to render</param>
        /// <param name="destRect">The size and position, in pixels, in the D2dGraphics's coordinate
        /// space, of the area in which the bitmap is drawn. If the rectangle is not well-ordered,
        /// nothing is drawn, but the D2dGraphics does not enter an error state.</param>
        /// <param name="opacity">A value between 0.0f and 1.0f, inclusive, that specifies an opacity value        
        /// to apply to the bitmap. This value is multiplied against the alpha values
        /// of the bitmap's contents.</param>
        /// <param name="interpolationMode">The interpolation mode to use if the bitmap is scaled or rotated 
        /// by the drawing operation</param>
        /// <param name="sourceRect">The size and position, in pixels in the bitmap's coordinate space, of the area
        /// within the bitmap to draw</param>
        public void DrawBitmap(D2dBitmap bmp, RectangleF destRect, float opacity, 
            D2dBitmapInterpolationMode interpolationMode, RectangleF sourceRect)
        {
            var drect = new SharpDX.RectangleF(destRect.X, destRect.Y, destRect.Right, destRect.Bottom);
            var srect = new SharpDX.RectangleF(sourceRect.X, sourceRect.Y, sourceRect.Right, sourceRect.Bottom);

            m_renderTarget.DrawBitmap(bmp.NativeBitmap, drect, opacity,
                (BitmapInterpolationMode)interpolationMode, srect);
        }
Example #11
0
 /// <summary>
 /// Draws the specified bitmap after scaling it to the size of the specifiedrectangle</summary>
 /// <param name="bmp">The bitmap to render</param>
 /// <param name="destRect">The size and position, in pixels, in the D2dGraphics's coordinate
 /// space, of the area in which the bitmap is drawn. If the rectangle is not well-ordered,
 /// nothing is drawn, but the D2dGraphics does not enter an error state.</param>
 /// <param name="opacity">A value between 0.0f and 1.0f, inclusive, that specifies an opacity value        
 /// to apply to the bitmap. This value is multiplied against the alpha values
 /// of the bitmap's contents.</param>
 /// <param name="interpolationMode">The interpolation mode to use if the bitmap is scaled or rotated 
 /// by the drawing operation</param>
 public void DrawBitmap(D2dBitmap bmp, RectangleF destRect, float opacity = 1.0f, D2dBitmapInterpolationMode interpolationMode = D2dBitmapInterpolationMode.Linear)
 {
     var rect = new SharpDX.RectangleF(destRect.X, destRect.Y, destRect.Right, destRect.Bottom);
     m_renderTarget.DrawBitmap(bmp.NativeBitmap, rect, opacity, (BitmapInterpolationMode)interpolationMode, null);
 }
Example #12
0
 /// <summary>
 /// Creates a new D2dBitmapBrush from the specified bitmap</summary>
 /// <param name="bitmap">The bitmap contents of the new brush</param>
 /// <returns>A new instance of D2dBitmapBrush</returns>
 public static D2dBitmapBrush CreateBitmapBrush(D2dBitmap bitmap)
 {
     return(s_gfx.CreateBitmapBrush(bitmap));
 }
Example #13
0
        internal D2dBitmapBrush(D2dGraphics owner, D2dBitmap bitmap)
            : base(owner)
        {
            m_bitmap = bitmap;

            m_extendModeX = D2dExtendMode.Clamp;
            m_extendModeY = D2dExtendMode.Clamp;
            m_location = new PointF(1, 1);
            m_interpolationMode = D2dBitmapInterpolationMode.Linear;
            Create();//to-do: it's dangerous to call a virtual method in a constructor; derived class may not be properly initialized!
        }