【问题标题】:saving a graphic file [duplicate]保存图形文件[重复]
【发布时间】:2018-05-04 15:45:21
【问题描述】:

我正在创建一个表单应用程序,在这个应用程序中我让用户绘制矩形、三角形、六边形等。我想将这些图形保存在一个文件中,并且我想在打开程序时使用它们。我的意思是使用它们像自然图形。我正在选择并更改我想要绘制的对象的颜色。如果我将此文件导入我的应用程序,则能够更改它的颜色

【问题讨论】:

  • 好吧,对我来说听起来像是一个计划。
  • 创建位图并在其中绘制,然后保存。
  • 在其 Paint 事件中使用 e.Graphics 对象绘制到位图或绘制到控件(如 Panel 或 PictureBox)上,然后使用 DrawToBitmap 并保存结果。 .
  • 我更改了我的问题,这不是我为我的问题环顾数小时的重复问题

标签: c# graphics


【解决方案1】:

像这样的。

// write
BinaryWriter Writer = new BinaryWriter(File.Open(FileName, FileMode.Create));;

Writer.Write(this.Point.X); Writer.Write(this.Point.Y); Writer.Write(this.Point.Z);
Writer.Write(this.Point.X); Writer.Write(this.Point.Y); Writer.Write(this.Point.Z);  
Writer.Write(this.Point.X); Writer.Write(this.Point.Y); Writer.Write(this.Point.Z);
Writer.Write(this.Point.X); Writer.Write(this.Point.Y); Writer.Write(this.Point.Z);    

Writer.Flush();
Writer.Close();

// read
BinaryReader Reader = new BinaryReader(File.Open(FileName, FileMode.Open));

this.Point.X = Reader.ReadDouble(); this.Point.Y = Reader.ReadDouble(); this.Point.Z = Reader.ReadDouble();    
this.Point.X = Reader.ReadDouble(); this.Point.Y = Reader.ReadDouble(); this.Point.Z = Reader.ReadDouble();    
this.Point.X = Reader.ReadDouble(); this.Point.Y = Reader.ReadDouble(); this.Point.Z = Reader.ReadDouble();    
this.Point.X = Reader.ReadDouble(); this.Point.Y = Reader.ReadDouble(); this.Point.Z = Reader.ReadDouble();

Reader.Close();

【讨论】:

    猜你喜欢
    • 2011-04-11
    • 2011-11-23
    • 2017-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-13
    • 2011-05-22
    • 2021-10-03
    相关资源
    最近更新 更多