コード例 #1
0
        /// <summary>
        /// 绘制缩略图
        /// </summary>
        /// <param name="g"></param>
        /// <param name="doc"></param>
        private void DrawPic(Graphics g, SvgDocument doc)
        {
            if (doc == null && doc.RootElement == null)
            {
                return;
            }
            SVG svgroot = doc.RootElement as SVG;

            if (svgroot == null)
            {
                return;
            }
            RectangleF rtf1;

            rtf1 = svgroot.ContentBounds;
            SizeF sf1 = vectorControl.DocumentSize;

            if (!rtf1.IsEmpty)
            {
                sf1 = rtf1.Size;
            }
            else
            {
                rtf1.Size = sf1;
            }
            SizeF sf2 = this.viewPic.Size;

            scale = GetScaleSingle(sf2, rtf1.Size);

            g.DrawRectangle(Pens.Black, offX, offY, scale * sf1.Width + 1, scale * sf1.Height + 1);
            g.FillRectangle(Brushes.White, offX, offY, scale * sf1.Width, scale * sf1.Height);

            using (Matrix matrix1 = new Matrix())
            {
                matrix1.Translate(-rtf1.X, -rtf1.Y, MatrixOrder.Prepend);
                matrix1.Scale(scale, scale, MatrixOrder.Append);
                matrix1.Translate(offX, offY, MatrixOrder.Append);
                Matrix matrix2 = svgroot.GraphTransform.Matrix.Clone();
                svgroot.GraphTransform.Matrix = matrix1;

                if (svgroot != null)
                {
                    svgroot.Draw(g, 0);
                }
                svgroot.GraphTransform.Matrix = matrix2;
            }
            RectangleF rtf3 = this.viewBounds;

            rtf3.Width  *= scale;
            rtf3.Height *= scale;
            //rtf3.Offset(-rtf1.X, -rtf1.Y);
            rtf3.X *= scale;
            rtf3.Y *= scale;
            rtf3.Offset(offX, offY);

            Pen tempPen = new Pen(Color.Blue, 2);

            g.TranslateTransform(-rtf1.X * scale, -rtf1.Y * scale);
            g.DrawRectangle(tempPen, Rectangle.Round(rtf3));
        }
コード例 #2
0
ファイル: PrintHelper.cs プロジェクト: github188/myitoppsp
        private void RenderTo(Graphics g)
        {
            setTJhide();
            SvgDocument svgdoc  = tlVectorControl1.SVGDocument;
            Matrix      matrix1 = new Matrix();
            Matrix      matrix2 = new Matrix();

            matrix1 = ((SVG)svgdoc.RootElement).GraphTransform.Matrix;
            matrix2.Multiply(matrix1);
            matrix1.Reset();
            matrix1.Multiply(g.Transform);
            g.ResetTransform();
            try
            {
                SVG svg1 = svgdoc.DocumentElement as SVG;
                svgdoc.BeginPrint = true;
                SmoothingMode mode1 = svgdoc.SmoothingMode;
                svgdoc.SmoothingMode = g.SmoothingMode;
                svg1.Draw(g, svgdoc.ControlTime);
                svgdoc.SmoothingMode = mode1;
                svgdoc.BeginPrint    = false;
            }
            finally
            {
                g.Transform = matrix1.Clone();
                matrix1.Reset();
                matrix1.Multiply(matrix2);
            }
            setTJshow();
        }
コード例 #3
0
ファイル: ImageFunc.cs プロジェクト: github188/myitoppsp
        public static Bitmap GetImageForURL(string sURL, SvgElement element)
        {
            Bitmap bitmap1 = null;

            try
            {
                if ((sURL.StartsWith("http://") || sURL.StartsWith("https://")) || sURL.StartsWith("file://"))
                {
                    WebRequest   request1  = WebRequest.Create(sURL);
                    WebResponse  response1 = request1.GetResponse();
                    Stream       stream1   = response1.GetResponseStream();
                    MemoryStream stream2   = new MemoryStream();
                    for (int num1 = stream1.ReadByte(); num1 != -1; num1 = stream1.ReadByte())
                    {
                        stream2.WriteByte((byte)num1);
                    }
                    if (!response1.ContentType.StartsWith("image/svg+xml"))
                    {
                        bitmap1 = (Bitmap)System.Drawing.Image.FromStream(stream2);
                    }
                    stream1.Close();
                    return(bitmap1);
                }
                string text1 = Path.GetExtension(sURL);
                if (text1.Trim().ToLower() == ".svg")
                {
                    SvgDocument document1 = SvgDocumentFactory.CreateDocumentFromFile(sURL);
                    if ((document1 != null) && (document1.DocumentElement is SVG))
                    {
                        SVG svg1 = (SVG)document1.DocumentElement;
                        bitmap1 = new Bitmap((int)svg1.Width, (int)svg1.Height);
                        Graphics graphics1 = Graphics.FromImage(bitmap1);
                        svg1.Draw(graphics1, element.OwnerDocument.ControlTime);
                        graphics1.Dispose();
                    }
                    return(bitmap1);
                }
                if (regex.IsMatch(sURL))                //Base64±àÂë×ÊÔ´
                {
                    string text2   = sURL.Substring(regex.Match(sURL).Length);
                    Stream stream1 = FromBase64String(text2);
                    if (stream1 != null)
                    {
                        bitmap1 = (Bitmap)System.Drawing.Image.FromStream(stream1);
                    }
                    return(bitmap1);
                }
//				System.Drawing.Image a= System.Drawing.Image.FromFile(sURL,true);
//				if(a.GetType().FullName=="System.Drawing.Imaging.Metafile")
//				{
//
//					Metafile wmf=(Metafile)Metafile.FromFile(sURL);
//					int aa=wmf.Width;
//					int bb=wmf.Height;
//					Bitmap bm=new Bitmap(wmf.Width,wmf.Height);
//					Graphics gr=Graphics.FromImage(bm);
//					RectangleF dest_bounds=new RectangleF(0,0,wmf.Width,wmf.Height);
//					RectangleF source_bounds=new RectangleF(0,0,wmf.Width,wmf.Height);
//					gr.DrawImage(wmf, dest_bounds, source_bounds, GraphicsUnit.Pixel);
//
////					MemoryStream stream4=new MemoryStream() ;
////					bm.Save(stream4,bm.RawFormat);
//					bm.Save("C:\\1.bmp",ImageFormat.Bmp);
//
//					bitmap1 = (Bitmap) System.Drawing.Image.FromFile("C:\\1.bmp");
//					MemoryStream stream3=new MemoryStream() ;
//					bitmap1.Save(stream3,bitmap1.RawFormat);
//					if (stream3 != null)
//					{
//						string text3 = ToBase64String(stream3);
//
//						(element as XmlElement).SetAttribute("href", SvgDocument.XLinkNamespace, text3);
//					}
//					 gr.Dispose();
//				}
                else
                {
                    try {
                        bitmap1 = (Bitmap)System.Drawing.Image.FromFile(sURL);
                    } catch {
                        bitmap1 = (Bitmap)System.Drawing.Image.FromFile(AppDomain.CurrentDomain.BaseDirectory + "\\" + sURL);
                    }
                    if (bitmap1 != null && !SvgDocument.BkImageLoad)
                    {
                        MemoryStream stream3 = new MemoryStream();
                        bitmap1.Save(stream3, bitmap1.RawFormat);
                        if (stream3 != null)
                        {
                            string text3 = ToBase64String(stream3);

                            (element as XmlElement).SetAttribute("href", SvgDocument.XLinkNamespace, text3);
                        }
                    }
                }
            }
            catch (Exception exception1)
            {
                throw exception1;
            }
            return(bitmap1);
        }