예제 #1
0
        public void DrawImageClipped(Gdi::Graphics g, Gdi::RectangleF clip)
        {
            clip.Intersect(imageArea);
            float cacheX = clip.X + 0.5f;

            if (offsetX > 0)
            {
                cacheX -= offsetX;
            }
            float cacheY = clip.Y + 0.5f;

            if (offsetY > 0)
            {
                cacheY -= offsetY;
            }
#if WIN32PINVOKE
            using (Gdi::Graphics gImg = Gdi::Graphics.FromImage(this.cache)){
                const int     SRCCOPY = 0x00CC0020;
                System.IntPtr dstDC   = g.GetHdc();
                System.IntPtr srcDC   = GetCacheHdc(dstDC);
                BitBlt(
                    dstDC, (int)clip.X, (int)clip.Y,
                    (int)clip.Width, (int)clip.Height,
                    srcDC, (int)cacheX, (int)cacheY,
                    SRCCOPY
                    );
                g.ReleaseHdc(dstDC);
            }
#else
            Gdi::RectangleF rectI = new Gdi::RectangleF(cacheX, cacheY, clip.Width, clip.Height);
            g.DrawImage(this.cache, clip, rectI, Gdi::GraphicsUnit.Pixel);
#endif
        }
예제 #2
0
 /// <summary>
 /// 枠付で矩形を塗り潰します。
 /// </summary>
 /// <param name="g">描画対象の矩形を指定します。</param>
 /// <param name="fill">矩形を塗り潰すのに使用するブラシを指定します。</param>
 /// <param name="frame">矩形の枠を描画する為のペンを指定します。</param>
 /// <param name="rect">矩形を指定します。</param>
 public static void FillRectangleFramed(Gdi::Graphics g, Gdi::Brush fill, Gdi::Pen frame, Gdi::Rectangle rect)
 {
     g.FillRectangle(fill, rect);
     rect.Width--;
     rect.Height--;
     g.DrawRectangle(frame, rect);
 }
예제 #3
0
파일: Form2.cs 프로젝트: akinomyoga/hnk
        void AllocatePictureImage()
        {
            if (this.backImage != null)
            {
                if (this.backImage.Width == this.pictureBox1.Width &&
                    this.backImage.Height == this.pictureBox1.Height)
                {
                    return;
                }
                this.FreePictureImage();
            }

            int w = this.pictureBox1.Width; if (w <= 0)
            {
                w = 1;
            }
            int h = this.pictureBox1.Height; if (h <= 0)

            {
                h = 1;
            }

            this.backImage    = new Gdi::Bitmap(w, h);
            this.foreImage    = new Gdi::Bitmap(w, h);
            this.foreGraphics = Gdi::Graphics.FromImage(this.foreImage);
            this.foreGraphics.Clear(Gdi::Color.Transparent);
            this.pictureBox1.BackgroundImage = this.backImage;
            this.pictureBox1.Image           = this.foreImage;
            this.UpdatePictureImage();
        }
예제 #4
0
 /// <summary>
 /// 矩形を塗り潰し、反転色で枠を描画します。
 /// </summary>
 /// <param name="g">描画対象の矩形を指定します。</param>
 /// <param name="fill">塗り潰すのに使用する色を指定します。</param>
 /// <param name="rect">対象の矩形を指定します。</param>
 public static void FillRectangleReverseDotFramed(Gdi::Graphics g, Gdi::Color fill, Gdi::Rectangle rect)
 {
     using (Gdi::SolidBrush brush = new Gdi::SolidBrush(fill))
         using (Gdi::Pen pen = new Gdi::Pen(~(afh.Drawing.Color32Argb)fill)){
             pen.DashStyle = Gdi::Drawing2D.DashStyle.Dot;
             FillRectangleFramed(g, brush, pen, rect);
         }
 }
예제 #5
0
        /// <summary>
        /// 指定した状態に応じた CheckBox を表示します。
        /// </summary>
        /// <param name="g">描画先の Graphics を指定します。</param>
        /// <param name="state">Check 状態を指定します。</param>
        /// <param name="enabled">CheckBox が有効になっているかどうかを指定します。</param>
        public void DrawBox(Gdi::Graphics g, bool?state, bool enabled)
        {
            Gdi::Rectangle src = rect;

            src.X += 14 * (state == null?1: (bool)state?2: 0);
            src.Y += 14 * (enabled?0:1);
            g.DrawImage(this.image, 0, 0, src, Gdi::GraphicsUnit.Pixel);
        }
예제 #6
0
 /// <summary>
 /// 指定した色の反転色で矩形枠を描画します。
 /// </summary>
 /// <param name="g">描画対象の矩形を指定します。</param>
 /// <param name="fill">矩形枠の反転色を指定します。</param>
 /// <param name="rect">対象の矩形を指定します。</param>
 public static void DrawRectangleReverseDotFramed(Gdi::Graphics g, Gdi::Color fill, Gdi::Rectangle rect)
 {
     using (Gdi::Pen pen = new Gdi::Pen(~(afh.Drawing.Color32Argb)fill)){
         pen.DashStyle = Gdi::Drawing2D.DashStyle.Dot;
         rect.Width--;
         rect.Height--;
         g.DrawRectangle(pen, rect);
     }
 }
예제 #7
0
파일: Form2.cs 프로젝트: akinomyoga/hnk
        static void DrawControlPoint(Gdi::Graphics g, Vector2 p1)
        {
            const int   W   = 3;
            Gdi::PointF pp1 = p1.ToPointF(); pp1.X -= W; pp1.Y -= W;
            Gdi::PointF pp2 = p1.ToPointF(); pp2.X += W; pp2.Y -= W;
            Gdi::PointF pp3 = p1.ToPointF(); pp3.X += W; pp3.Y += W;
            Gdi::PointF pp4 = p1.ToPointF(); pp4.X -= W; pp4.Y += W;

            g.DrawPolygon(Gdi::Pens.Red, new[] { pp1, pp2, pp3, pp4 });
        }
예제 #8
0
        public GraphicsClipRectStore(Gdi::Graphics g)
        {
            this.g = g;
            Gdi::RectangleF rectF = g.ClipBounds;

            this.rect = new Gdi::Rectangle(
                (int)rectF.X, (int)rectF.Y,
                (int)rectF.Width, (int)rectF.Height
                );
        }
예제 #9
0
파일: Form2.cs 프로젝트: akinomyoga/hnk
        static void DrawBezier(Gdi::Graphics g, Vector2 p1, Vector2 q, Vector2 p2)
        {
            const int N   = 100;
            Vector2   pp1 = p1;

            for (int i = 1; i <= N; i++)
            {
                double  t   = (1.0 / N) * i;
                Vector2 pp2 = t * t * p2 + 2 * t * (1 - t) * q + (1 - t) * (1 - t) * p1;
                g.DrawLine(Gdi::Pens.Lime, pp1.ToPointF(), pp2.ToPointF());
                pp1 = pp2;
            }
        }
예제 #10
0
        private void Draw(Gdi::Graphics g)
        {
            if (this.bmp != null)
            {
                //g.DrawLine(Gdi::Pens.Blue,0,0,100,100);

                /*
                 * g.DrawImageUnscaledAndClipped(
                 *      bmp,
                 *      new Gdi::Rectangle(0,0,this.Width,this.Height)
                 *      );
                 * //*/
                g.Clear(this.BackColor);
                g.DrawImage(this.bmp, rcDest, rcSrc, Gdi::GraphicsUnit.Pixel);
            }
        }
예제 #11
0
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            base.WndProc(ref m);
            if (m.Result == (System.IntPtr) 0)
            {
                return;
            }

            if (m.Msg == (int)mwg.Win32.WM.PAINT)
            {
                Gdi::Graphics g = this.CreateGraphics();
                g.Clear(Gdi::Color.Red);
                g.Dispose();

                m.Result = (System.IntPtr) 0;
            }
        }
예제 #12
0
파일: Form2.cs 프로젝트: akinomyoga/hnk
 void UpdatePictureImage()
 {
     if (this.targetImage != null && this.backImage != null)
     {
         using (Gdi::Graphics g = Gdi::Graphics.FromImage(this.backImage)){
             double sx = (double)this.targetImage.Width / this.backImage.Width;
             double sy = (double)this.targetImage.Height / this.backImage.Height;
             double s  = System.Math.Max(sx, sy) * 1.2;
             float  x  = (float)System.Math.Round(0.5 * (this.backImage.Width - this.targetImage.Width / s));
             float  y  = (float)System.Math.Round(0.5 * (this.backImage.Height - this.targetImage.Height / s));
             float  w  = (float)System.Math.Round(this.targetImage.Width / s);
             float  h  = (float)System.Math.Round(this.targetImage.Height / s);
             g.Clear(Gdi::Color.Transparent);
             g.DrawImage(this.targetImage, x, y, w, h);
             this.deform.SetRectangle(x, y, w, h);
             this.deform.imageWidth  = this.targetImage.Width;
             this.deform.imageHeight = this.targetImage.Height;
             this.deform.Draw(this.foreGraphics);
         }
     }
 }
예제 #13
0
        void ITreeNodeIcon.DrawIcon(Gdi::Graphics g, Gdi::Rectangle rect, TreeNode node)
        {
            switch (this.type)
            {
            case IconType.Image:
                g.DrawImage(this.img, rect);
                break;

            case IconType.Icon:
                g.DrawIcon(this.icon, rect);
                break;

            case IconType.ImageList:
                g.DrawImage(this.list.Images[this.index], rect);
                break;

            case IconType.ClippedImage:
                g.DrawImage(this.img, rect, this.rect, Gdi::GraphicsUnit.Pixel);
                break;
            }
        }
예제 #14
0
        /// <summary>
        /// 描画する背景画像の情報を更新します。
        /// </summary>
        /// <param name="image">描画する背景画像を指定します。</param>
        /// <param name="scaleX">画像の表示 X 倍率を指定します。</param>
        /// <param name="scaleY">画像の表示 Y 倍率を指定します。</param>
        /// <param name="offsetX">画像の表示 X 位置を指定します。</param>
        /// <param name="offsetY">画像の表示 Y 位置を指定します。</param>
        /// <param name="displaySize">画面上の表示の大きさを指定します。</param>
        public void UpdateImage(Gdi::Image image, float scaleX, float scaleY, float offsetX, float offsetY, Gdi::Size displaySize)
        {
            if (image == this.original &&
                scaleX == this.scaleX && scaleY == this.scaleY &&
                offsetX == this.offsetX && offsetY == this.offsetY &&
                displaySize == this.displaySize
                )
            {
                return;
            }

            this.original    = image;
            this.scaleX      = scaleX;
            this.scaleY      = scaleY;
            this.offsetX     = offsetX;
            this.offsetY     = offsetY;
            this.displaySize = displaySize;

            imageArea = new Gdi::RectangleF(offsetX, offsetY, image.Width * scaleX, image.Height * scaleY);
            // 画面座標での描画領域
            Gdi::RectangleF srcRectD = Gdi::RectangleF.Intersect(new Gdi::RectangleF(Gdi::PointF.Empty, displaySize), imageArea);
            // 画像座標での描画領域
            Gdi::RectangleF srcRectI = new Gdi::RectangleF(
                (srcRectD.X - offsetX) / scaleX,
                (srcRectD.Y - offsetY) / scaleY,
                srcRectD.Width / scaleX,
                srcRectD.Height / scaleY
                );

            srcRectD.X = 0;
            srcRectD.Y = 0;

            this.FreeCache();
            this.cache = new System.Drawing.Bitmap((int)(srcRectD.Width + .5f), (int)(srcRectD.Height + .5f));
            using (Gdi::Graphics g = Gdi::Graphics.FromImage(this.cache))
                g.DrawImage(image, srcRectD, srcRectI, Gdi::GraphicsUnit.Pixel);

            ImageEnlight(this.cache);
        }
예제 #15
0
파일: Form2.cs 프로젝트: akinomyoga/hnk
 public void Draw(Gdi::Graphics g)
 {
     g.Clear(Gdi::Color.Transparent);
     g.DrawLine(Gdi::Pens.Blue, this.p1.ToPointF(), this.q1.ToPointF());
     g.DrawLine(Gdi::Pens.Blue, this.p2.ToPointF(), this.q1.ToPointF());
     g.DrawLine(Gdi::Pens.Blue, this.p2.ToPointF(), this.q2.ToPointF());
     g.DrawLine(Gdi::Pens.Blue, this.p3.ToPointF(), this.q2.ToPointF());
     g.DrawLine(Gdi::Pens.Blue, this.p3.ToPointF(), this.q3.ToPointF());
     g.DrawLine(Gdi::Pens.Blue, this.p4.ToPointF(), this.q3.ToPointF());
     g.DrawLine(Gdi::Pens.Blue, this.p4.ToPointF(), this.q4.ToPointF());
     g.DrawLine(Gdi::Pens.Blue, this.p1.ToPointF(), this.q4.ToPointF());
     DrawBezier(g, this.p1, this.q1, this.p2);
     DrawBezier(g, this.p2, this.q2, this.p3);
     DrawBezier(g, this.p3, this.q3, this.p4);
     DrawBezier(g, this.p4, this.q4, this.p1);
     DrawControlPoint(g, this.p1);
     DrawControlPoint(g, this.p2);
     DrawControlPoint(g, this.p3);
     DrawControlPoint(g, this.p4);
     DrawControlPoint(g, this.q1);
     DrawControlPoint(g, this.q2);
     DrawControlPoint(g, this.q3);
     DrawControlPoint(g, this.q4);
 }
예제 #16
0
 public GraphicsClipRegionStore(Gdi::Graphics g)
 {
     this.g    = g;
     this.clip = g.Clip.Clone();
 }
예제 #17
0
 static GraphicsUtils()
 {
     g = Gdi::Graphics.FromImage(dummy);
 }
예제 #18
0
 public GraphicsTransformStore(Gdi::Graphics g)
 {
     this.g   = g;
     this.mat = this.g.Transform.Clone();
 }
예제 #19
0
 public GdiDrawer(Gdi::Graphics g)
 {
     this.g = g;
 }
예제 #20
0
파일: [!]GDI.cs 프로젝트: akinomyoga/afh
 /// <summary>
 ///
 /// </summary>
 /// <param name="g">
 /// 作成元の Graphics を指定します。
 /// 元の Graphics を操作する前に必ずこのインスタンスの Dispose を呼び出して下さい。
 /// </param>
 public DeviceContext(Gdi::Graphics g)
 {
     this.hdc     = g.GetHdc();
     this.dispose = new System.Action <HDC>(g.ReleaseHdc);
 }