• 大小: 2.85MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-11
  • 语言: C#
  • 标签: SVG  WINFRO  image  png  

资源简介

svg矢量图的使用,将svg矢量图展示在pictureBox上,拖动可以应用到其他设计软件上

资源截图

代码片段和文件信息

using Svg;
using SvgApplyDemo.Properties;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Net;
using System.Windows.Forms;

namespace SvgApplyDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            InitForm();
            InitContent();
        }

        #region property
        private SvgDocument _document;
        private int _effectScaleWidth = 252;
        private int _effectScaleHeight = 40;
        public static string ApplicationDataTempPath
        {
            get
            {
                var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + “\\SystemData\\Temp1\\“;
                if (!Directory.Exists(path)) Directory.CreateDirectory(path);
                return path;
            }
        }
        #endregion

        #region method       

        /// 
        /// 将SVG文件转换为位图图像。
        /// 

        /// SVG图像的全路径。
        /// 返回转换位图图像。
        public Image GetImageFromSVG(string filePath)
        {
            try
            {
                _document = SvgDocument.Open(filePath);
                return ZoomImage(_document.Draw() _effectScaleWidth _effectScaleHeight);
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// 
        /// 等比例缩放图片
        /// 

        /// 
        /// 
        /// 
        /// 
        private Bitmap ZoomImage(Bitmap bitmap int destWidth int destHeight)
        {
            try
            {
                Image sourImage = bitmap;
                int width = 0 height = 0;
                //按比例缩放           
                int sourWidth = sourImage.Width;
                int sourHeight = sourImage.Height;
                if (sourHeight > destHeight || sourWidth > destWidth)
                {
                    if ((sourWidth * destHeight) > (sourHeight * destWidth))
                    {
                        width = destWidth;
                        height = (destWidth * sourHeight) / sourWidth;
                    }
                    else
                    {
                        height = destHeight;
                        width = (sourWidth * destHeight) / sourHeight;
                    }
                }
                else
                {
                    width = sourWidth;
                    height = sourHeight;
                }
                Bitmap destBitmap = new Bitmap(destWidth destHeight);
                Graphics g = Graphics.FromImage(destBitmap);
                g.Clear(Color.Transparent);
                //设置画布的描绘质量         
                g

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2019-04-12 13:35  WinFormSvgApplyDemo\
     目录           0  2019-04-12 13:37  WinFormSvgApplyDemo\.git\
     文件         107  2019-04-12 13:37  WinFormSvgApplyDemo\.git\COMMIT_EDITMSG
     文件         311  2019-04-12 13:34  WinFormSvgApplyDemo\.git\config
     文件          73  2019-04-12 13:34  WinFormSvgApplyDemo\.git\description
     文件          23  2019-04-12 13:34  WinFormSvgApplyDemo\.git\HEAD
     目录           0  2019-04-12 13:34  WinFormSvgApplyDemo\.git\hooks\
     文件         478  2019-04-12 13:34  WinFormSvgApplyDemo\.git\hooks\applypatch-msg.sample
     文件         896  2019-04-12 13:34  WinFormSvgApplyDemo\.git\hooks\commit-msg.sample
     文件         189  2019-04-12 13:34  WinFormSvgApplyDemo\.git\hooks\post-update.sample
     文件         424  2019-04-12 13:34  WinFormSvgApplyDemo\.git\hooks\pre-applypatch.sample
     文件        1642  2019-04-12 13:34  WinFormSvgApplyDemo\.git\hooks\pre-commit.sample
     文件        1239  2019-04-12 13:34  WinFormSvgApplyDemo\.git\hooks\prepare-commit-msg.sample
     文件        1348  2019-04-12 13:34  WinFormSvgApplyDemo\.git\hooks\pre-push.sample
     文件        4951  2019-04-12 13:34  WinFormSvgApplyDemo\.git\hooks\pre-rebase.sample
     文件         544  2019-04-12 13:34  WinFormSvgApplyDemo\.git\hooks\pre-receive.sample
     文件        3610  2019-04-12 13:34  WinFormSvgApplyDemo\.git\hooks\update.sample
     文件        5530  2019-04-12 13:37  WinFormSvgApplyDemo\.git\index
     目录           0  2019-04-12 13:34  WinFormSvgApplyDemo\.git\info\
     文件         240  2019-04-12 13:34  WinFormSvgApplyDemo\.git\info\exclude
     目录           0  2019-04-12 13:34  WinFormSvgApplyDemo\.git\logs\
     文件         444  2019-04-12 13:37  WinFormSvgApplyDemo\.git\logs\HEAD
     目录           0  2019-04-12 13:34  WinFormSvgApplyDemo\.git\logs\refs\
     目录           0  2019-04-12 13:34  WinFormSvgApplyDemo\.git\logs\refs\heads\
     文件         444  2019-04-12 13:37  WinFormSvgApplyDemo\.git\logs\refs\heads\master
     目录           0  2019-04-12 13:34  WinFormSvgApplyDemo\.git\logs\refs\remotes\
     目录           0  2019-04-12 13:34  WinFormSvgApplyDemo\.git\logs\refs\remotes\origin\
     文件         195  2019-04-12 13:34  WinFormSvgApplyDemo\.git\logs\refs\remotes\origin\HEAD
     文件         149  2019-04-12 13:37  WinFormSvgApplyDemo\.git\logs\refs\remotes\origin\master
     目录           0  2019-04-12 13:34  WinFormSvgApplyDemo\.git\objects\
     目录           0  2019-04-12 13:37  WinFormSvgApplyDemo\.git\objects\01\
............此处省略178个文件信息

评论

共有 条评论