コード例 #1
0
        private ToolStripMenuItem SetFonts()
        {
            ToolStripMenuItem menuItem = new ToolStripMenuItem("Insert Font");

            List <string> fonts = new List <string>();

            foreach (System.Windows.Media.FontFamily font in System.Windows.Media.Fonts.SystemFontFamilies) //WPF fonts
            {
                fonts.Add(font.FamilyNames.Values.First());
            }
            fonts.Sort();

            foreach (string fontName in fonts)
            {
                Bitmap bmp = null;
                try
                {
                    int size = 20;
                    //bmp = new Bitmap(4 * size, 5 * size / 4);
                    //Graphics g = Graphics.FromImage(bmp);
                    //g.SmoothingMode = SmoothingMode.HighQuality;
                    //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    //g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    //g.DrawString("Basic", new Font(new FontFamily(fontName), size, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.Black, 1, 1);

                    System.Windows.Media.DrawingVisual dv = new System.Windows.Media.DrawingVisual();
                    using (System.Windows.Media.DrawingContext dc = dv.RenderOpen())
                    {
                        dc.DrawRectangle(System.Windows.Media.Brushes.White, null, new System.Windows.Rect(0, 0, 4 * size, 5 * size / 4));
                        dc.DrawText(new System.Windows.Media.FormattedText("Basic", System.Globalization.CultureInfo.InvariantCulture,
                                                                           System.Windows.FlowDirection.LeftToRight, new System.Windows.Media.Typeface(fontName), size,
                                                                           System.Windows.Media.Brushes.Black), new System.Windows.Point(1, 1));
                    }
                    System.Windows.Media.Imaging.RenderTargetBitmap rtb = new System.Windows.Media.Imaging.RenderTargetBitmap(4 * size, 5 * size / 4, 96, 96, System.Windows.Media.PixelFormats.Pbgra32);
                    rtb.Render(dv);
                    rtb.Freeze();
                    MemoryStream stream = new MemoryStream();
                    System.Windows.Media.Imaging.BitmapEncoder encoder = new System.Windows.Media.Imaging.BmpBitmapEncoder();
                    encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(rtb));
                    encoder.Save(stream);
                    bmp = new Bitmap(stream);
                }
                catch
                {
                }

                ToolStripMenuItem item = new ToolStripMenuItem(fontName, bmp, Insert);
                item.ImageScaling = ToolStripItemImageScaling.None;

                menuItem.DropDownItems.Add(item);
            }

            return(menuItem);
        }
コード例 #2
0
        // Do printing to a set of bitmaps using the XPS/WPF path. This is used for testing support.
        public System.Windows.Media.Imaging.BitmapSource[] PrintXpsBitmaps(float dpi)
        {
            // Set up and position everything.
            printingToBitmaps      = true;
            printPreviewInProgress = false;
            SetupPrinting();

            if (totalPages <= 0)
            {
                return(new System.Windows.Media.Imaging.BitmapSource[0]);
            }

            PrintEventArgs printArgs = new PrintEventArgs();
            List <System.Windows.Media.Imaging.BitmapSource> bitmapList = new List <System.Windows.Media.Imaging.BitmapSource>();

            BeginPrint(this, printArgs);

            float paperWidth = pageSettings.PaperSize.Width, paperHeight = pageSettings.PaperSize.Height;

            if (pageSettings.Landscape)
            {
                float temp = paperWidth; paperWidth = paperHeight; paperHeight = temp;
            }

            var paginator = new Paginator(this, 0, new SizeF(paperWidth, paperHeight), pageSettings.Margins, dpi, false);

            for (int pageNumber = 0; pageNumber < paginator.PageCount; ++pageNumber)
            {
                DocumentPage docPage = paginator.GetPage(pageNumber);

                paperWidth  = (float)PointsToHundreths(docPage.Size.Width);
                paperHeight = (float)PointsToHundreths(docPage.Size.Height);

                var bitmapNew = new System.Windows.Media.Imaging.RenderTargetBitmap(
                    (int)Math.Round(paperWidth * dpi / 100F),
                    (int)Math.Round(paperHeight * dpi / 100F),
                    dpi, dpi, System.Windows.Media.PixelFormats.Pbgra32);
                bitmapNew.Render(docPage.Visual);
                bitmapNew.Freeze();
                bitmapList.Add(bitmapNew);
            }

            EndPrint(this, printArgs);

            return(bitmapList.ToArray());
        }
コード例 #3
0
ファイル: BasicPrinting.cs プロジェクト: petergolde/PurplePen
        // Do printing to a set of bitmaps using the XPS/WPF path. This is used for testing support.
        public System.Windows.Media.Imaging.BitmapSource[] PrintXpsBitmaps(float dpi)
        {
            // Set up and position everything.
            printingToBitmaps = true;
            printPreviewInProgress = false;
            SetupPrinting();

            if (totalPages <= 0)
                return new System.Windows.Media.Imaging.BitmapSource[0];

            PrintEventArgs printArgs = new PrintEventArgs();
            List<System.Windows.Media.Imaging.BitmapSource> bitmapList = new List<System.Windows.Media.Imaging.BitmapSource>();

            BeginPrint(this, printArgs);

            float paperWidth = pageSettings.PaperSize.Width, paperHeight = pageSettings.PaperSize.Height;
            if (pageSettings.Landscape) {
                float temp = paperWidth; paperWidth = paperHeight; paperHeight = temp;
            }

            var paginator = new Paginator(this, 0, new SizeF(paperWidth, paperHeight), pageSettings.Margins, dpi, false);

            for (int pageNumber = 0; pageNumber < paginator.PageCount; ++pageNumber) {
                DocumentPage docPage = paginator.GetPage(pageNumber);

                paperWidth = (float)PointsToHundreths(docPage.Size.Width);
                paperHeight = (float)PointsToHundreths(docPage.Size.Height);

                var bitmapNew = new System.Windows.Media.Imaging.RenderTargetBitmap(
                    (int) Math.Round(paperWidth * dpi / 100F),
                    (int) Math.Round(paperHeight * dpi / 100F),
                    dpi, dpi, System.Windows.Media.PixelFormats.Pbgra32);
                bitmapNew.Render(docPage.Visual);
                bitmapNew.Freeze();
                bitmapList.Add(bitmapNew);
            }

            EndPrint(this, printArgs);

            return bitmapList.ToArray();
        }
コード例 #4
0
ファイル: CurveSurface.cs プロジェクト: WildGenie/863
        ///<summary>生成3D模型</summary>
        public void genModel()
        {
            //数据初始化
            //定义参数
            double maxX3D = parent.para.Limit.X, maxY3D = parent.para.Limit.Y, maxZ3D = parent.para.Limit.Z;  // 3D场景最大坐标
            int    xcount = 12, zcount = 24, xcountData, zcountData = 25;

            // x y 方向数目,x为月数,z为小时数,其中,xcount表征月分,xcountData为数据的x方向个数
            //zcount为0-23点,但zcountData为0-24点,多一个数据,同理,xcount中,增加一个数,全年下为12.31日
            xcountData = samplePoints.GroupBy(p => p.zDate.Date).Count();

            MeshGeometry3D mesh = new MeshGeometry3D();

            double devx = maxX3D / (xcount), devy = maxY3D / parent.maxYValue, devz = maxZ3D / (zcount);

            allpoint = new Point3D[xcountData, zcountData];

            double tx, tz;
            int    di, dj;

            di = 0;
            DateTime olddate = samplePoints.OrderBy(p => p.zDate).First().zDate.Date;

            foreach (var e in samplePoints.OrderBy(p => p.zDate))
            {
                //di = e.zDate.Month - 1;
                if (e.zDate.Date != olddate)
                {
                    di++;
                    olddate = e.zDate.Date;
                }

                dj = e.zDate.Hour;

                allpoint[di, dj] = new Point3D((double)((e.zDate - parent.startDate).TotalDays - 1) / ((parent.endDate - parent.startDate).TotalDays - 1) * maxX3D, devy * (double)e.zValue, -devz * dj);
                if (dj == 0) //赋第24点,以本日0代替
                {
                    allpoint[di, zcountData - 1] = new Point3D((double)((e.zDate - parent.startDate).TotalDays - 1) / ((parent.endDate - parent.startDate).TotalDays - 1) * maxX3D, devy * (double)e.zValue, -devz * (zcountData - 1));
                }
            }


            allpoint = insertZPoint(allpoint, 2); //z插点
            allpoint = insertXPoint(allpoint, 2); //x插点



            for (int i = 0; i < allpoint.GetLength(0); i++)  //加positions
            {
                for (int j = 0; j < allpoint.GetLength(1); j++)
                {
                    mesh.Positions.Add(allpoint[i, j]);
                    tx = 1.0 * i / allpoint.GetLength(0);
                    tz = 1.0 * j / allpoint.GetLength(1);
                    mesh.TextureCoordinates.Add(new Point(tx, tz));
                }
            }

            for (int i = 0; i < allpoint.GetLength(0) - 1; i++) // 加三角索引
            {
                for (int j = 0; j < allpoint.GetLength(1) - 1; j++)
                {
                    mesh.TriangleIndices.Add(j + i * allpoint.GetLength(1));
                    mesh.TriangleIndices.Add(j + (i + 1) * allpoint.GetLength(1));
                    mesh.TriangleIndices.Add(j + 1 + i * allpoint.GetLength(1));
                    mesh.TriangleIndices.Add(j + 1 + i * allpoint.GetLength(1));
                    mesh.TriangleIndices.Add(j + (i + 1) * allpoint.GetLength(1));
                    mesh.TriangleIndices.Add(j + 1 + (i + 1) * allpoint.GetLength(1));
                }
            }


            //===============  曲面材质
            Canvas panelLine = new Canvas();

            panelLine.Width  = devx * (parent.endDate - parent.startDate).TotalDays;
            panelLine.Height = devz * 23 * 30;
            //色变化说明:最高255,0,0最低0,255,0;从低到高变化顺序1:R 0->255,2:G 255->0;

            double x, y, maxy = 10, miny = 0, maxh = panelLine.Height, maxw = panelLine.Width;
            double w = maxw / (allpoint.GetLength(0) - 1), h = maxh / (allpoint.GetLength(1) - 1);
            double v;
            Color  c1, c2;
            byte   cr, cg, cb = 0;

            maxy = 0; miny = 10000;
            for (int i = 0; i < allpoint.GetLength(0) - 1; i++)
            {
                for (int j = 0; j < allpoint.GetLength(1) - 1; j++)
                {
                    if (allpoint[i, j].Y > maxy)
                    {
                        maxy = allpoint[i, j].Y;
                    }
                    if (allpoint[i, j].Y < miny)
                    {
                        miny = allpoint[i, j].Y;
                    }
                }
            }

            Point3D lastpoint = allpoint[allpoint.GetLength(0) - 1, allpoint.GetLength(1) - 1];

            for (int i = 0; i < allpoint.GetLength(0) - 1; i++)
            {
                for (int j = 0; j < allpoint.GetLength(1) - 1; j++)
                {
                    x = allpoint[i, j].X / lastpoint.X * maxw;
                    y = allpoint[i, j].Z / lastpoint.Z * maxh;

                    w = (allpoint[i + 1, j].X - allpoint[i, j].X) / lastpoint.X * maxw;

                    double temp = 1;// .2;//新疆怪需求,人为加大最大值,以避免纯红
                    v  = (allpoint[i, j].Y - miny) / (maxy * temp - miny) * 511;
                    cr = v > 255 ? (byte)255 : (byte)v;
                    cg = v > 255 ? (byte)(255 - (v - 256)) : (byte)255;
                    c1 = Color.FromRgb(cr, cg, cb);
                    v  = (allpoint[i + 1, j + 1].Y - miny) / (maxy * temp - miny) * 511;
                    cr = v > 255 ? (byte)255 : (byte)v;
                    cg = v > 255 ? (byte)(255 - (v - 256)) : (byte)255;
                    c2 = Color.FromRgb(cr, cg, cb);

                    RectangleGeometry rect = new RectangleGeometry(new Rect(x, y, w, h));
                    rect.Freeze();
                    Path pr = new Path();
                    pr.Data = rect;
                    LinearGradientBrush cbrush = new LinearGradientBrush(c1, c2, new Point(0, 0), new Point(1, 1));
                    pr.Fill            = cbrush;
                    pr.StrokeThickness = 0;

                    panelLine.Children.Add(pr);
                }
            }
            panelLine.Measure(new System.Windows.Size(h, w));
            panelLine.Arrange(new Rect(0, 0, h, w));



            System.Windows.Media.Imaging.RenderTargetBitmap renderTarget = new System.Windows.Media.Imaging.RenderTargetBitmap((int)panelLine.Width, (int)panelLine.Height, 96, 96, PixelFormats.Pbgra32);
            renderTarget.Render(panelLine);
            renderTarget.Freeze();
            curveBrush = new ImageBrush(renderTarget);
            DiffuseMaterial mat = new DiffuseMaterial(curveBrush);

            mat.Freeze();

            model = new GeometryModel3D(mesh, mat);

            model.BackMaterial = mat;
        }