2010-11-09 92 views
0

我在这个新的XML世界,因此我有这个XML文件:XML文件为JPG文件

<?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#创建这个新的.jpg文件VS2008。可能吗? 在此先感谢

回答

2

是的,这绝对是可以在C#中完成的。这将是我建议的步骤:

  1. 定义XML文件中的基本图形(椭圆,直线,文本等)和绘图命令之间的映射在System.Drawing命名空间,看看你是否找到了对应的方法在Graphics类中为每个“命令”在XML文件中。
  2. 编写代码以反序列化XML文档。
  3. 绘制原语。
  4. 保存为JPEG图像。

绘制代码会是这个样子:

// 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); 
+0

感谢0xA3执行我能够创建JPG文件:) – George 2010-11-10 18:34:03