Ejemplo n.º 1
0
 public static MauiDrawable?CreateDrawable(this ImagePaint imagePaint)
 {
     return(new MauiDrawable
     {
         Background = imagePaint
     });
 }
Ejemplo n.º 2
0
		public static Drawable? CreateDrawable(this ImagePaint imagePaint, Context? context)
		{
			var drawable = new MauiDrawable(context);
			drawable.SetBackground(imagePaint);

			return drawable;
		}
        public static Drawable?CreateDrawable(this ImagePaint imagePaint)
        {
            var drawable = new MauiDrawable();

            drawable.SetPaint(imagePaint);

            return(drawable);
        }
Ejemplo n.º 4
0
            private string Line(ImagePaint imgp)
            {
                var brushAngle = (Int32) (mBaseArcStart + (mValue - mMinValue)*mBaseArcSweep/(mMaxValue - mMinValue))%
                                 360;
                var needleAngle = brushAngle*Math.PI/180;

                var points = new PointF[3];
                var brush1 = Brushes.White;
                var brush2 = Brushes.White;
                var brush3 = Brushes.White;
                var brush4 = Brushes.White;

                var subcol = (((brushAngle + 225)%180)*100/180);
                var subcol2 = (((brushAngle + 135)%180)*100/180);

                imgp.Graphic = Graphics.FromImage(gaugeBitmap);
                imgp.Graphic.FillEllipse(new SolidBrush(mNeedleColor2), Center.X - mNeedleWidth*3,
                                         Center.Y - mNeedleWidth*3, mNeedleWidth*6, mNeedleWidth*6);
                switch (mNeedleColor1)
                {
                    case NeedleColorEnum.Gray:
                        brush1 = new SolidBrush(Color.FromArgb(80 + subcol, 80 + subcol, 80 + subcol));
                        brush2 = new SolidBrush(Color.FromArgb(180 - subcol, 180 - subcol, 180 - subcol));
                        brush3 = new SolidBrush(Color.FromArgb(80 + subcol2, 80 + subcol2, 80 + subcol2));
                        brush4 = new SolidBrush(Color.FromArgb(180 - subcol2, 180 - subcol2, 180 - subcol2));
                        imgp.Graphic.DrawEllipse(Pens.Gray, Center.X - mNeedleWidth*3, Center.Y - mNeedleWidth*3,
                                                 mNeedleWidth*6, mNeedleWidth*6);
                        break;
                    case NeedleColorEnum.Red:
                        brush1 = new SolidBrush(Color.FromArgb(145 + subcol, subcol, subcol));
                        brush2 = new SolidBrush(Color.FromArgb(245 - subcol, 100 - subcol, 100 - subcol));
                        brush3 = new SolidBrush(Color.FromArgb(145 + subcol2, subcol2, subcol2));
                        brush4 = new SolidBrush(Color.FromArgb(245 - subcol2, 100 - subcol2, 100 - subcol2));
                        imgp.Graphic.DrawEllipse(Pens.Red, Center.X - mNeedleWidth*3, Center.Y - mNeedleWidth*3,
                                                 mNeedleWidth*6, mNeedleWidth*6);
                        break;
                    case NeedleColorEnum.Green:
                        brush1 = new SolidBrush(Color.FromArgb(subcol, 145 + subcol, subcol));
                        brush2 = new SolidBrush(Color.FromArgb(100 - subcol, 245 - subcol, 100 - subcol));
                        brush3 = new SolidBrush(Color.FromArgb(subcol2, 145 + subcol2, subcol2));
                        brush4 = new SolidBrush(Color.FromArgb(100 - subcol2, 245 - subcol2, 100 - subcol2));
                        imgp.Graphic.DrawEllipse(Pens.Green, Center.X - mNeedleWidth*3, Center.Y - mNeedleWidth*3,
                                                 mNeedleWidth*6, mNeedleWidth*6);
                        break;
                    case NeedleColorEnum.Blue:
                        brush1 = new SolidBrush(Color.FromArgb(subcol, subcol, 145 + subcol));
                        brush2 = new SolidBrush(Color.FromArgb(100 - subcol, 100 - subcol, 245 - subcol));
                        brush3 = new SolidBrush(Color.FromArgb(subcol2, subcol2, 145 + subcol2));
                        brush4 = new SolidBrush(Color.FromArgb(100 - subcol2, 100 - subcol2, 245 - subcol2));
                        imgp.Graphic.DrawEllipse(Pens.Blue, Center.X - mNeedleWidth*3, Center.Y - mNeedleWidth*3,
                                                 mNeedleWidth*6, mNeedleWidth*6);
                        break;
                    case NeedleColorEnum.Magenta:
                        brush1 = new SolidBrush(Color.FromArgb(subcol, 145 + subcol, 145 + subcol));
                        brush2 = new SolidBrush(Color.FromArgb(100 - subcol, 245 - subcol, 245 - subcol));
                        brush3 = new SolidBrush(Color.FromArgb(subcol2, 145 + subcol2, 145 + subcol2));
                        brush4 = new SolidBrush(Color.FromArgb(100 - subcol2, 245 - subcol2, 245 - subcol2));
                        imgp.Graphic.DrawEllipse(Pens.Magenta, Center.X - mNeedleWidth*3, Center.Y - mNeedleWidth*3,
                                                 mNeedleWidth*6, mNeedleWidth*6);
                        break;
                    case NeedleColorEnum.Violet:
                        brush1 = new SolidBrush(Color.FromArgb(145 + subcol, subcol, 145 + subcol));
                        brush2 = new SolidBrush(Color.FromArgb(245 - subcol, 100 - subcol, 245 - subcol));
                        brush3 = new SolidBrush(Color.FromArgb(145 + subcol2, subcol2, 145 + subcol2));
                        brush4 = new SolidBrush(Color.FromArgb(245 - subcol2, 100 - subcol2, 245 - subcol2));
                        imgp.Graphic.DrawEllipse(Pens.Violet, Center.X - mNeedleWidth*3, Center.Y - mNeedleWidth*3,
                                                 mNeedleWidth*6, mNeedleWidth*6);
                        break;
                    case NeedleColorEnum.Yellow:
                        brush1 = new SolidBrush(Color.FromArgb(145 + subcol, 145 + subcol, subcol));
                        brush2 = new SolidBrush(Color.FromArgb(245 - subcol, 245 - subcol, 100 - subcol));
                        brush3 = new SolidBrush(Color.FromArgb(145 + subcol2, 145 + subcol2, subcol2));
                        brush4 = new SolidBrush(Color.FromArgb(245 - subcol2, 245 - subcol2, 100 - subcol2));
                        imgp.Graphic.DrawEllipse(Pens.Yellow, Center.X - mNeedleWidth * 3, Center.Y - mNeedleWidth * 3,
                                                 mNeedleWidth*6, mNeedleWidth*6);
                        break;
                }

                if (Math.Floor((Single) (((brushAngle + 225)%360)/180.0)) == 0)
                {
                    var brushBucket = brush1;
                    brush1 = brush2;
                    brush2 = brushBucket;
                }

                if (Math.Floor((Single) (((brushAngle + 135)%360)/180.0)) == 0)
                {
                    brush4 = brush3;
                }

                points[0].X = (Single) (Center.X + mNeedleRadius*Math.Cos(needleAngle));
                points[0].Y = (Single) (Center.Y + mNeedleRadius*Math.Sin(needleAngle));
                points[1].X = (Single) (Center.X - mNeedleRadius/20*Math.Cos(needleAngle));
                points[1].Y = (Single) (Center.Y - mNeedleRadius/20*Math.Sin(needleAngle));
                points[2].X =
                    (Single)
                    (Center.X - mNeedleRadius/5*Math.Cos(needleAngle) + mNeedleWidth*2*Math.Cos(needleAngle + Math.PI/2));
                points[2].Y =
                    (Single)
                    (Center.Y - mNeedleRadius/5*Math.Sin(needleAngle) + mNeedleWidth*2*Math.Sin(needleAngle + Math.PI/2));
                imgp.Graphic.FillPolygon(brush1, points);

                points[2].X =
                    (Single)
                    (Center.X - mNeedleRadius/5*Math.Cos(needleAngle) + mNeedleWidth*2*Math.Cos(needleAngle - Math.PI/2));
                points[2].Y =
                    (Single)
                    (Center.Y - mNeedleRadius/5*Math.Sin(needleAngle) + mNeedleWidth*2*Math.Sin(needleAngle - Math.PI/2));
                imgp.Graphic.FillPolygon(brush2, points);

                points[0].X = (Single) (Center.X - (mNeedleRadius/20 - 1)*Math.Cos(needleAngle));
                points[0].Y = (Single) (Center.Y - (mNeedleRadius/20 - 1)*Math.Sin(needleAngle));
                points[1].X =
                    (Single)
                    (Center.X - mNeedleRadius/5*Math.Cos(needleAngle) + mNeedleWidth*2*Math.Cos(needleAngle + Math.PI/2));
                points[1].Y =
                    (Single)
                    (Center.Y - mNeedleRadius/5*Math.Sin(needleAngle) + mNeedleWidth*2*Math.Sin(needleAngle + Math.PI/2));
                points[2].X =
                    (Single)
                    (Center.X - mNeedleRadius/5*Math.Cos(needleAngle) + mNeedleWidth*2*Math.Cos(needleAngle - Math.PI/2));
                points[2].Y =
                    (Single)
                    (Center.Y - mNeedleRadius/5*Math.Sin(needleAngle) + mNeedleWidth*2*Math.Sin(needleAngle - Math.PI/2));
                imgp.Graphic.FillPolygon(brush4, points);

                points[0].X = (Single) (Center.X - mNeedleRadius/20*Math.Cos(needleAngle));
                points[0].Y = (Single) (Center.Y - mNeedleRadius/20*Math.Sin(needleAngle));
                points[1].X = (Single) (Center.X + mNeedleRadius*Math.Cos(needleAngle));
                points[1].Y = (Single) (Center.Y + mNeedleRadius*Math.Sin(needleAngle));

                imgp.Graphic.DrawLine(new Pen(mNeedleColor2), Center.X, Center.Y, points[0].X, points[0].Y);
                imgp.Graphic.DrawLine(new Pen(mNeedleColor2), Center.X, Center.Y, points[1].X, points[1].Y);

                var rect = new Rectangle(10, 10, 40, 15); //定义矩形,参数为起点横
                for (var i = 0; i < mRangeColor.Count(); i++)
                {
                    rect.Location=new Point(210,20*i+40);
                    var b1 = new SolidBrush(mRangeColor[i]);//定义单色画刷
                    var b2 = new SolidBrush(Color.Black);//定义单色画刷
                    imgp.Graphic.FillRectangle(b1, rect);
                    imgp.Graphic.DrawString(mRangeText[i], new Font("宋体", 8, FontStyle.Bold), b2, new PointF(214, 20 * i + 42));
                }

                var url = Utils.UrlPath("仪表盘", "GIF");
                gaugeBitmap.Save(url, ImageFormat.Gif);

                return url;
            }
Ejemplo n.º 5
0
            private void ImageBack2(GraphicsPath gp, Graphics ggr, ImagePaint imgp)
            {
                float countValue = 0;
                var counter1 = 0;
                while (countValue <= (mMaxValue - mMinValue))
                {
                    var valueText = (mMinValue + countValue).ToString(mScaleNumbersFormat);
                    ggr.ResetTransform();
                    var boundingBox = ggr.MeasureString(valueText, imgp.Font, -1, StringFormat.GenericTypographic);

                    gp.Reset();
                    gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesMajorOuterRadius,
                                                mCenter.Y - mScaleLinesMajorOuterRadius,
                                                2 * mScaleLinesMajorOuterRadius, 2 * mScaleLinesMajorOuterRadius));
                    gp.Reverse();
                    gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesMajorInnerRadius,
                                                mCenter.Y - mScaleLinesMajorInnerRadius,
                                                2 * mScaleLinesMajorInnerRadius, 2 * mScaleLinesMajorInnerRadius));
                    gp.Reverse();
                    ggr.SetClip(gp);

                    ggr.DrawLine(new Pen(mScaleLinesMajorColor, mScaleLinesMajorWidth),
                                 (Center.X), (Center.Y),
                                 (Single)
                                 (Center.X +
                                  2 * mScaleLinesMajorOuterRadius *
                                  Math.Cos((mBaseArcStart + countValue * mBaseArcSweep / (mMaxValue - mMinValue)) * Math.PI /
                                           180.0)),
                                 (Single)
                                 (Center.Y +
                                  2 * mScaleLinesMajorOuterRadius *
                                  Math.Sin((mBaseArcStart + countValue * mBaseArcSweep / (mMaxValue - mMinValue)) * Math.PI /
                                           180.0)));

                    gp.Reset();
                    gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesMinorOuterRadius,
                                                mCenter.Y - mScaleLinesMinorOuterRadius,
                                                2 * mScaleLinesMinorOuterRadius, 2 * mScaleLinesMinorOuterRadius));
                    gp.Reverse();
                    gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesMinorInnerRadius,
                                                mCenter.Y - mScaleLinesMinorInnerRadius,
                                                2 * mScaleLinesMinorInnerRadius, 2 * mScaleLinesMinorInnerRadius));
                    gp.Reverse();
                    ggr.SetClip(gp);

                    ImageBack3(countValue, gp, ggr, imgp);

                    if (mScaleNumbersRotation != 0)
                    {
                        ggr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                        ggr.RotateTransform(90.0F + mBaseArcStart + countValue * mBaseArcSweep / (mMaxValue - mMinValue));
                    }
                    ggr.TranslateTransform(
                        (Single)
                        (Center.X +
                         mScaleNumbersRadius *
                         Math.Cos((mBaseArcStart + countValue * mBaseArcSweep / (mMaxValue - mMinValue)) * Math.PI / 180.0f)),
                        (Single)
                        (Center.Y +
                         mScaleNumbersRadius *
                         Math.Sin((mBaseArcStart + countValue * mBaseArcSweep / (mMaxValue - mMinValue)) * Math.PI / 180.0f)),
                        MatrixOrder.Append);

                    if (counter1 >= ScaleNumbersStartScaleLine - 1)
                    {
                        ggr.DrawString(valueText, imgp.Font, new SolidBrush(mScaleNumbersColor), -boundingBox.Width / 2,
                                       -fontBoundY1 - (fontBoundY2 - fontBoundY1 + 1) / 2,
                                       StringFormat.GenericTypographic);
                    }

                    countValue += mScaleLinesMajorStepValue;
                    counter1++;
                }
                ggr.ResetTransform();
                ggr.SetClip(imgp.ClientRectangle);
            }
Ejemplo n.º 6
0
            //画刻度
            private void ImageBack1(GraphicsPath gp, Graphics ggr, ImagePaint imgp)
            {
                for (var counter = 0; counter < mRangeEndValue.Length; counter++)
                {
                    if (!(mRangeEndValue[counter] > mRangeStartValue[counter]) || !mRangeEnabled[counter])
                    {
                        continue;
                    }

                    var rangeStartAngle = mBaseArcStart +(mRangeStartValue[counter] - mMinValue) * mBaseArcSweep /(mMaxValue - mMinValue);
                    var rangeSweepAngle = (mRangeEndValue[counter] - mRangeStartValue[counter]) * mBaseArcSweep / (mMaxValue - mMinValue);
                    gp.Reset();
                    gp.AddPie(
                        new Rectangle(mCenter.X - mRangeOuterRadius[counter],
                                      mCenter.Y - mRangeOuterRadius[counter], 2 * mRangeOuterRadius[counter],
                                      2 * mRangeOuterRadius[counter]), rangeStartAngle, rangeSweepAngle);
                    gp.Reverse();
                    gp.AddPie(
                        new Rectangle(mCenter.X - mRangeInnerRadius[counter],
                                      mCenter.Y - mRangeInnerRadius[counter], 2 * mRangeInnerRadius[counter],
                                      2 * mRangeInnerRadius[counter]), rangeStartAngle, rangeSweepAngle);
                    gp.Reverse();
                    ggr.SetClip(gp);
                    //填充
                    ggr.FillPie(new SolidBrush(mRangeColor[counter]),
                                new Rectangle(mCenter.X - mRangeOuterRadius[counter],
                                              mCenter.Y - mRangeOuterRadius[counter],
                                              2 * mRangeOuterRadius[counter], 2 * mRangeOuterRadius[counter]),
                                rangeStartAngle, rangeSweepAngle);
                }
                ggr.SetClip(imgp.ClientRectangle);

                if (mBaseArcRadius > 0)
                {
                    ggr.DrawArc(new Pen(mBaseArcColor, mBaseArcWidth),
                                new Rectangle(mCenter.X - mBaseArcRadius, mCenter.Y - mBaseArcRadius,
                                              2 * mBaseArcRadius, 2 * mBaseArcRadius), mBaseArcStart, mBaseArcSweep);
                }
            }
Ejemplo n.º 7
0
            public string YibiaoPic(ImagePaint imgp)
            {
                Value = imgp.Value;
                imgp.Font = new Font("宋体", 9);
                if (drawGaugeBackground)
                {
                    drawGaugeBackground = false;
                    FindFontBounds();

                    gaugeBitmap = new Bitmap(imgp.Width, imgp.Height);
                    var ggr = Graphics.FromImage(gaugeBitmap);
                    imgp.Graphic = Graphics.FromImage(gaugeBitmap);
                    ggr.FillRectangle(new SolidBrush(imgp.BackColor), imgp.ClientRectangle);
                    ggr.SmoothingMode = SmoothingMode.HighQuality;
                    ggr.PixelOffsetMode = PixelOffsetMode.HighQuality;

                    var gp = new GraphicsPath();

                    ImageBack1(gp, ggr, imgp);
                    ImageBack2(gp, ggr, imgp);

                    if (mScaleNumbersRotation != 0)
                    {
                        ggr.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
                    }

                    for (var counter = 0; counter < mCapText.Length; counter++)
                    {
                        if (mCapText[counter] != "")
                        {
                            ggr.DrawString(mCapText[counter], imgp.Font, new SolidBrush(mCapColor[counter]),mCapPosition[counter].X, mCapPosition[counter].Y,StringFormat.GenericTypographic);
                        }
                    }
                    ggr.Dispose();
                    gp.Dispose();
                }
                   var url = Line(imgp);
                   gaugeBitmap.Dispose();
                   return url;
            }
Ejemplo n.º 8
0
            public void ImageBack3(Single countValue, GraphicsPath gp, Graphics ggr, ImagePaint imgp)
            {
                if (countValue < (mMaxValue - mMinValue))
                {
                    for (var counter2 = 1; counter2 <= mScaleLinesMinorNumOf; counter2++)
                    {
                        if (((mScaleLinesMinorNumOf % 2) == 1) &&
                            ((mScaleLinesMinorNumOf / 2) + 1 == counter2))
                        {
                            gp.Reset();
                            gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesInterOuterRadius,
                                                        mCenter.Y - mScaleLinesInterOuterRadius,
                                                        2 * mScaleLinesInterOuterRadius,
                                                        2 * mScaleLinesInterOuterRadius));
                            gp.Reverse();
                            gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesInterInnerRadius,
                                                        mCenter.Y - mScaleLinesInterInnerRadius,
                                                        2 * mScaleLinesInterInnerRadius,
                                                        2 * mScaleLinesInterInnerRadius));
                            gp.Reverse();
                            ggr.SetClip(gp);

                            ggr.DrawLine(new Pen(mScaleLinesInterColor, mScaleLinesInterWidth),
                                         (Center.X),
                                         (Center.Y),
                                         (Single)
                                         (Center.X +
                                          2 * mScaleLinesInterOuterRadius *
                                          Math.Cos((mBaseArcStart +
                                                    countValue * mBaseArcSweep / (mMaxValue - mMinValue) +
                                                    counter2 * mBaseArcSweep /
                                                    ((
                                                         ((mMaxValue - mMinValue) / mScaleLinesMajorStepValue)) *
                                                     (mScaleLinesMinorNumOf + 1))) * Math.PI / 180.0)),
                                         (Single)
                                         (Center.Y +
                                          2 * mScaleLinesInterOuterRadius *
                                          Math.Sin((mBaseArcStart +
                                                    countValue * mBaseArcSweep / (mMaxValue - mMinValue) +
                                                    counter2 * mBaseArcSweep /
                                                    ((
                                                         ((mMaxValue - mMinValue) / mScaleLinesMajorStepValue)) *
                                                     (mScaleLinesMinorNumOf + 1))) * Math.PI / 180.0)));

                            gp.Reset();
                            gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesMinorOuterRadius,
                                                        mCenter.Y - mScaleLinesMinorOuterRadius,
                                                        2 * mScaleLinesMinorOuterRadius,
                                                        2 * mScaleLinesMinorOuterRadius));
                            gp.Reverse();
                            gp.AddEllipse(new Rectangle(mCenter.X - mScaleLinesMinorInnerRadius,
                                                        mCenter.Y - mScaleLinesMinorInnerRadius,
                                                        2 * mScaleLinesMinorInnerRadius,
                                                        2 * mScaleLinesMinorInnerRadius));
                            gp.Reverse();
                            ggr.SetClip(gp);
                        }
                        else
                        {
                            ggr.DrawLine(new Pen(mScaleLinesMinorColor, mScaleLinesMinorWidth),
                                         (Center.X),
                                         (Center.Y),
                                         (Single)
                                         (Center.X +
                                          2 * mScaleLinesMinorOuterRadius *
                                          Math.Cos((mBaseArcStart +
                                                    countValue * mBaseArcSweep / (mMaxValue - mMinValue) +
                                                    counter2 * mBaseArcSweep /
                                                    ((
                                                         ((mMaxValue - mMinValue) / mScaleLinesMajorStepValue)) *
                                                     (mScaleLinesMinorNumOf + 1))) * Math.PI / 180.0)),
                                         (Single)
                                         (Center.Y +
                                          2 * mScaleLinesMinorOuterRadius *
                                          Math.Sin((mBaseArcStart +
                                                    countValue * mBaseArcSweep / (mMaxValue - mMinValue) +
                                                    counter2 * mBaseArcSweep /
                                                    ((
                                                         ((mMaxValue - mMinValue) / mScaleLinesMajorStepValue)) *
                                                     (mScaleLinesMinorNumOf + 1))) * Math.PI / 180.0)));
                        }
                    }
                }
                ggr.SetClip(imgp.ClientRectangle);
            }
 public void SetPaint(ImagePaint imagePaint)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 10
0
 public static WBrush?CreateBrush(this ImagePaint imagePaint)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 11
0
 public void SetBorderBrush(ImagePaint imagePaint)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 12
0
 public void SetBackground(ImagePaint imagePaint)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 13
0
 public static CALayer?CreateCALayer(this ImagePaint imagePaint, CGRect frame = default)
 {
     throw new NotImplementedException();
 }