需要帮助 - C#打开文件,bmp文件或二进制文件 [英] HELP NEEDED - C# opening a file, bmp file, or binary

查看:308
本文介绍了需要帮助 - C#打开文件,bmp文件或二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有点新C#,愚蠢的问题,我想读.bmp文件数据......或二进制文件数据



常用C长时间,这让我感到悲伤!



我知道这可能是最简单的问题......但是在线查找,找不到简单的答案?



想以编程方式执行此操作...无需对话框....



如何轻松打开文件C#?



如何保存和关闭文件?



谢谢。

解决方案

使用<$ c $打开位图(不仅仅是* .BMP) c> System.Drawing.Bitmap 构造函数:

http://msdn.microsoft.com/en-us/library/0cbhe98f%28v=vs.110%29.aspx [ ^ ]。



或二进制文件数据?哪有这回事。一切,任何文件都是二进制的。您可以打开任何文件。接下来做什么?这取决于。请参阅:

http://msdn.microsoft.com /en-us/library/system.io.binaryreader.aspx [ ^ ]。



如何在C#中轻松打开文件?错误的目标。你想要正确地做事。以最简单的方式做所有事情的愿望并不容易,这是通向挫折和死路的最短途径。做得好。努力学习。轻松永远是主人的结果;没有别的办法。







成员2113297写道:

我需要读出文件中的字节序列,并将它们发送出一个端口......这是我的目标。

你刚读完了部分,如您的评论中所示。它只适用于不太大的文件,因为你一次读取它并需要将它们全部保存在内存中。对于更大的文件 - 见上文。



要发送到端口,请使用 System.IO.Ports.SerialPort

http://msdn.microsoft.com/en-us/library/system.io.ports.serialport%28v=vs.110%29.aspx [ ^ ]。



通常,串口通信是在一个单独的线程中完成的。



-SA

Kinda new with C#, stupid question, i want to read in .bmp file data...or a binary file data

used regular C long time, this is giving me grief!

I know this is probably the simplest question...but looking on line, cant find a simple answer?

Want to do this programmatically...no dialog box needed....

How do I open a file easily in C#?

How do I save and close the file?

Thanks.

解决方案

Bitmaps (not just *.BMP) are opened with System.Drawing.Bitmap constructor:
http://msdn.microsoft.com/en-us/library/0cbhe98f%28v=vs.110%29.aspx[^].

"Or a binary file data"? There is no such thing. Everything, any file, is binary. You can open any file. What to do next? it depends. Please see:
http://msdn.microsoft.com/en-us/library/system.io.binaryreader.aspx[^].

"How do I open a file easily in C#?" Wrong goal. You want to do things properly. The desire to do everything "the easiest way" does not make like easier, this is the shortest path to frustrations and dead ends. Do things properly. Learn hard. The ease is always a result of mastership; there is no other way around.

[EDIT]

Member 2113297 wrote:

I need to read out the sequence of bytes in the file, and send them out a port… that is my objective.

You just did the read part, as it is shown in your comment. It works only for not too big files, as you read it all at once and need to keep it all in memory. For bigger files — see above.

For sending to the port, please use System.IO.Ports.SerialPort:
http://msdn.microsoft.com/en-us/library/system.io.ports.serialport%28v=vs.110%29.aspx[^].

Usually, serial port communications are done in a separate thread.

—SA


这篇关于需要帮助 - C#打开文件,bmp文件或二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆