Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 12-Nov-13 14:57pm
v2

1 solution

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
 
Share this answer
 
v6
Comments
Member 2113297 12-Nov-13 22:14pm    
Well I tried this:

byte[] readBuffer = System.IO.File.ReadAllBytes(fileFontPick);

i was loading a .bmp file...wanted to get each byte of data...

it read in all the data...in byte format

then...used the write method, to write a file back with a ll the data...that worked.

I guess the question is, is there something special about reading individula bytes out the way i show, and how your suggestion would do it?

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

Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900