当前位置:网站首页>Export all SVG files in the specified path into pictures in PNG format (thumbnail or original size)
Export all SVG files in the specified path into pictures in PNG format (thumbnail or original size)
2022-04-23 07:54:00 【Dake mountain man】
WPF Of XAML file (Main.xaml):
<Window x:Class="SVG2Image.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:SVG2Image"
mc:Ignorable="d" Title="MainWindow" Height="350" Width="525">
<Grid>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left" Margin="388,21,0,0" VerticalAlignment="Top"
Width="103" Click="button_Click" Height="23" />
<Label x:Name="label" Content=" Size " HorizontalAlignment="Left" Margin="54,21,0,0" VerticalAlignment="Top" />
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="100,21,0,0" TextWrapping="Wrap"
Text="128,64,32,16" VerticalAlignment="Top" Width="272" />
</Grid>
</Window>
CS Code :(Main.xaml.cs)
using Svg;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SVG2Image
{
/// <summary>
/// Will specify all the SVG File export to PNG Wait for the format of the picture ( The size of the thumbnail or the original )
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
string savePath = @"d:\output";
string svgFilePath = @"E:\SVG";
private void button_Click(object sender, RoutedEventArgs e)
{
string sizeText = textBox.Text;
if (string.IsNullOrEmpty(sizeText)) sizeText = "64"; // Default 64 Pixel size
string[] sizeArray = sizeText.Split(',');
List<int> listSize = new List<int>();
try
{
foreach (string s in sizeArray)
{
listSize.Add(int.Parse(s));
}
}
catch (Exception exc)
{
MessageBox.Show(" Incorrect size entered , Must be a number ( Groups are separated by commas );\r\n" + exc.ToString());
return;
}
if (!Directory.Exists(savePath))
{
Directory.CreateDirectory(savePath);
}
string[] arraySvgFiles = Directory.GetFiles(svgFilePath, "*.svg");
foreach (string file in arraySvgFiles)
{
string fileName = System.IO.Path.GetFileNameWithoutExtension(file);
try
{
string svgFileContents = File.ReadAllText(file, Encoding.UTF8);
var byteArray = Encoding.ASCII.GetBytes(svgFileContents);
string saveFileName = savePath + @"\" + fileName + @"{0}_{1}.png";
foreach (int sz in listSize)
{
using (var stream = new MemoryStream(byteArray))
{
var svgDocument = SvgDocument.Open(stream);
svgDocument.Width = sz;
svgDocument.Height = sz;
var bitmap = svgDocument.Draw();
bitmap.Save(string.Format(saveFileName, sz, sz), ImageFormat.Png);
}
}
}
catch (Exception exc)
{
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(savePath + @"\error.txt", true))
{
sw.WriteLine(fileName);// Directly append to the end of the file , Line break
}
}
}
}
}
}

版权声明
本文为[Dake mountain man]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230625378714.html
边栏推荐
- 【NLP笔记】CRF原理初探
- Unity gets a resource that is referenced by those resources
- Xamarin版的C# SVG路径解析器
- Houdini fluid > > particle fluid export to unity note
- 庄懂的TA笔记(七)<Lambert+Phong+Shadow+3EvColor+AO>
- Unity screen adaptation
- Towords Open World Object Detection
- Judge whether the beginning and end of the string contain target parameters: startswith() and endswith() methods
- Common markdown grammar learning
- Protobuf use
猜你喜欢

三分钟教你用Houdini流体>>解算粒子流体水滴

Dropping Pixels for Adversarial Robustness

TA notes of Zhuang understand (VII) < Lambert + Phong + shadow + 3evcolor + Ao >

Unity get real geographic map application terrain notes

Protobuf use

C#控制相机,旋转,拖拽观察脚本(类似Scenes观察方式)

Common markdown grammar learning

Teach-Repeat-Replan: A Complete and Robust System for Aggressive Flight in Complex Environments

关于U盘数据提示RAW,需要格式化,数据恢复笔记

Houdini > rigid body, rigid body breaking RBD
随机推荐
第四章 无形资产
About USB flash drive data prompt raw, need to format, data recovery notes
快速排序
Moment. Format of format method function in JS
Nodejs (II) read files synchronously and asynchronously
ES6使用递归实现深拷贝
The problem of exporting excel form with wireframe and internal spacing of form by using web form
Quick sort
Houdini>建筑道路可变,学习过程笔记
根据某一指定的表名、列名及列值来向前或向后N条查相关列值的SQL自定义标量值函数
取得所有点列表中的最大值GetMaxPoint
C#控制相机,旋转,拖拽观察脚本(类似Scenes观察方式)
Double sided shader
大学学习路线规划建议贴
How does Apache Hudi accelerate traditional batch mode?
Nodejs (I) event driven programming
SampleCameraFilter
FUEL: Fast UAV Exploration using Incremental Frontier Structure and Hierarchical Planning
Nodejs (VI) sub process operation
Understanding the role of individual units in a deep neural networks