当前位置:编程学习 > wap >>

请教mobile里如何画饼图的问题!

我的开发环境是VC2005+Widows mobile pro6 SDK,我仔细看了一下GDI函数,发现没有CreateEllipticRgn或者Pie之类的函数可以画饼图,我就用Ellipse画了一个椭圆,然后用直线切成饼图,但是现在不知道怎么给每个封闭区域的饼图填充颜色,或者说不知道怎么创建HRGN区域,请高手指点,不胜感激!!! --------------------编程问答-------------------- mark --------------------编程问答-------------------- 效果图:

/// <summary>
        /// 画扇形
        /// </summary>
        /// <param name="x">保存写文字的扇形中心X坐标</param>
        /// <param name="y">保存写文字的扇形中心Y坐标</param>
        /// <param name="LORR">保存是否在左还是在右</param>
        /// <param name="OnOrOut">保存字在图上还画出</param>
        /// <param name="temp">扇形的起始角度</param>
        /// <param name="Ps">椭圆的点集</param>
        /// <param name="Pt">拄体的点集</param>
        /// <param name="cAngle">扇形的角度大小</param>
        /// <param name="falg">标识有是否超过了450</param>
        /// <param name="x1">扇形的椭圆的点X坐标</param>
        /// <param name="y1">扇形的椭圆的点Y坐标</param>
        /// <param name="tempX">扇形起始的椭圆的点X坐标</param>
        /// <param name="tempY">扇形起始的椭圆的点Y坐标</param>
        /// <param name="i">第几个扇形</param>
        /// <param name="PointNumber">扇形起始的椭圆的点X坐标</param>
        private void DrawSector(double[] x, double[] y, int[] LORR, double[] cAngles, bool[] OnOrOut, ref double temp, Point[] Ps,
            ref Point[] Pt, double cAngle, ref int x1, ref int y1, ref int tempX, ref int tempY,
            int i, int PointNumber, ref int falg)
        {
            double j = 0;
            int k = 0, m = 0;
            int cA = 0; // 每个扇形椭圆上的点
            int MaxNubmer = Convert.ToInt32(180 / Addangle); // 椭圆上最多的点
            for (j = temp, k = 0; j <= (temp + cAngle); k++)
            {
                Ps[k] = new Point();
                //计算椭圆上的点
                x1 = Convert.ToInt32(a * System.Math.Sin(j / 360.0 * 2 * System.Math.PI) + dOx);
                y1 = Convert.ToInt32(b * System.Math.Cos(j / 360.0 * 2 * System.Math.PI) + dOy);
                Ps[k].X = x1;
                Ps[k].Y = y1;
                if (k == (PointNumber / 2))
                {
                    OnOrOut[i] = (Math.PI * b * (cAngle / 360)) > (fFontSize * 4 / 3);//求的孤长来判断是否字在图上还画出来
                    x[i] = (x1 + dOx) / 2;
                    y[i] = (y1 + dOy) / 2;
                    if (j % 360 >= 180 && j % 360 < 270)
                    {
                        LORR[i] = 1;
                        if (OnOrOut[i])//在图上文本向上移动
                            y[i] -= fFontSize;//在一项限文本向上移动
                    }
                    if (j % 360 >= 270 && j % 360 < 360)
                        LORR[i] = 1;
                    if (j % 360 >= 0 && j % 360 < 90)
                        LORR[i] = 2;
                    if (j % 360 >= 90 && j % 360 < 180)
                    {
                        LORR[i] = 2;
                        if (OnOrOut[i])//在图上文本向上移动
                            y[i] -= fFontSize;//在二项限文本向上移动
                    }
                    cAngles[i] = j;
                }
                if (cAngle == 0)
                {
                    x[i] = (x1 + dOx) / 2;
                    y[i] = (y1 + dOy) / 2;
                    if (temp % 360 >= 180 && temp % 360 < 270)
                        LORR[i] = 1;
                    if (temp % 360 >= 270 && temp % 360 < 360)
                        LORR[i] = 1;
                    if (temp % 360 >= 0 && temp % 360 < 90)
                        LORR[i] = 2;
                    if (temp % 360 >= 90 && temp % 360 < 180)
                        LORR[i] = 2;
                    cAngles[i] = j;
                }
                if (cAngle > 0 && ((j < 450 && j >= 270) || (j < 90 && falg == 1)))
                {
                    if (j == temp || cA == 0)
                    {
                        if (j < 90 && temp + cAngle > 90) // 一种小于90度情况
                            cA = Convert.ToInt32((90 - j) / Addangle);
                        else if (temp + cAngle > 450)
                            cA = Convert.ToInt32((450 - j) / Addangle);
                        else
                            cA = Convert.ToInt32((temp + cAngle - j) / Addangle);
                        if (cA > MaxNubmer)
                            cA = MaxNubmer;
                        Pt = new Point[2 * cA];
                        m = 0;
                    }
                    if (j >= 270 && temp <= 270)
                    {

                        Pt[m].X = x1;
                        Pt[m].Y = y1;
                        Pt[2 * cA - m - 1].X = x1;
                        Pt[2 * cA - m - 1].Y = y1 + height;
                        m++;
                    }
                    else
                    {
                        Pt[m].X = x1;
                        Pt[m].Y = y1;
                        Pt[2 * cA - m - 1].X = x1;
                        Pt[2 * cA - m - 1].Y = y1 + height;
                        m++;
                    }
                }
                j = j + Addangle;
            }
            Ps[PointNumber] = new Point();
            Ps[PointNumber].X = (int)dOx;
            Ps[PointNumber].Y = (int)dOy;
            FillPolygon(Brush, Ps, DrawGraphicsP);
            if (cA > 0)
            {
                if (cColors.Length == 2 * dDataNumber.Length)
                    Brush = new SolidBrush(cColors[i % (cColors.Length / 2) + (cColors.Length / 2)]);
                else
                {
                    int[] rgb = new int[3];
                    rgb[0] = Convert.ToInt32(cColors[i].R);
                    rgb[1] = Convert.ToInt32(cColors[i].G);
                    rgb[2] = Convert.ToInt32(cColors[i].B);
                    float[] hls = new float[3];
                    RgbToHsl(rgb[0], rgb[1], rgb[2], ref hls[0], ref hls[1], ref hls[2]);
                    hls[1] -= 40f;
                    HslToRgb(ref rgb[0], ref rgb[1], ref rgb[2], hls[0], hls[1], hls[2]);
                    Brush = new SolidBrush(Color.FromArgb(rgb[0], rgb[1], rgb[2]));

                }
                FillPolygon(Brush, Pt, DrawGraphicsP);
            }
            temp = j - Addangle;
            if (temp >= 360)
            {
                falg = 1;
                temp %= 360;
            }
            DisposeAll();
        }
--------------------编程问答-------------------- 楼主看看这个帖子:
http://topic.csdn.net/u/20091012/13/34D54C31-FA0D-4AE5-BB5F-6E9B21D96AB7.html --------------------编程问答-------------------- 我试一下,关键是VC能不能使用,还有就是如何填充颜色?
补充:移动开发 ,  Windows Phone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,