我是这个xml世界的新手,因此我有这个xml文件:
<?xml version="1.0"?>
<Graphics xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Graphics>
<PropertiesGraphicsEllipse>
<Left>56</Left>
<Top>43.709333795560333</Top>
<Right>225</Right>
<Bottom>193.70933379556033</Bottom>
<LineWidth>1</LineWidth>
<ObjectColor>
<A>255</A>
<R>0</R>
<G>0</G>
<B>0</B>
<ScA>1</ScA>
<ScR>0</ScR>
<ScG>0</ScG>
<ScB>0</ScB>
</ObjectColor>
</PropertiesGraphicsEllipse>
<PropertiesGraphicsLine>
<Start>
<X>345</X>
<Y>21.709333795560333</Y>
</Start>
<End>
<X>371</X>
<Y>279.70933379556033</Y>
</End>
<LineWidth>6</LineWidth>
<ObjectColor>
<A>255</A>
<R>182</R>
<G>0</G>
<B>0</B>
<ScA>1</ScA>
<ScR>0.4677838</ScR>
<ScG>0</ScG>
<ScB>0</ScB>
</ObjectColor>
</PropertiesGraphicsLine>
<PropertiesGraphicsText>
<Text>Hola Mundo</Text>
<Left>473</Left>
<Top>109.70933379556033</Top>
<Right>649</Right>
<Bottom>218.70933379556033</Bottom>
<ObjectColor>
<A>255</A>
<R>21</R>
<G>208</G>
<B>0</B>
<ScA>1</ScA>
<ScR>0.007499032</ScR>
<ScG>0.630757153</ScG>
<ScB>0</ScB>
</ObjectColor>
<TextFontSize>12</TextFontSize>
<TextFontFamilyName>Verdana</TextFontFamilyName>
<TextFontStyle>Normal</TextFontStyle>
<TextFontWeight>Normal</TextFontWeight>
<TextFontStretch>Normal</TextFontStretch>
</PropertiesGraphicsText>
</Graphics>
</Graphics>
我正在尝试使用C#VS2008从这个文件创建一个新的.jpg文件。可能吗? 提前致谢
答案 0 :(得分:2)
是的,这绝对可以用C#做。这些将是我建议的步骤:
System.Drawing
命名空间中的绘图命令之间的映射,看看是否在Graphics
类中找到了相应的方法对于XML文件中的每个“命令”。 绘图代码如下所示:
// create a bitmap object with a default size
Bitmap bmp = new Bitmap(1024, 768);
// get a graphics object where we are able to draw on
Graphics g = Graphics.FromImage(bmp);
// for each PropertiesGraphicsEllipse draw an ellipse
// g.DrawEllipse(...);
// for each PropertiesGraphicsLine draw a line
// g.DrawLine(...);
// for each PropertiesGraphicsText write text
g.DrawString("Hola Mundo", new Font("Verdana", 12),
new SolidBrush(Color.FromArgb(255, 21, 208, 0)), new PointF(473F, 109.7F));
// save as JPEG
bmp.Save(@"C:\tmp\image.jpg", ImageFormat.Jpeg);