Click here to Skip to main content
12,548,135 members (49,120 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# file Handling
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 dialog box needed....

How do I open a file easily in C#?

How do I save and close the file?

Posted 12-Nov-13 14:40pm
Updated 12-Nov-13 14:57pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Bitmaps (not just *.BMP) are opened with System.Drawing.Bitmap constructor:[^].

"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:[^].

"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.


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:[^].

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

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 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.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.161021.1 | Last Updated 12 Nov 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100