Hello,
I am developing a video recording (mjpeg) system which records large
binary files. I need to read the JPEG data from the binary file and
create a bitmap object to be displayed. Unfortunately I cannot find an
efficient way to do this in C#. I need to do this at 10fps+ with 1hour+
data files.
My current approach is read a byte[] from the filestream, then create a
MemoryStream to the created byte[] and then a bitmap from the memory
stream. This seems very excessive and is quite CPU and memory
intensive.
A bitmap constructor like this would be great:
public Bitmap(byte[] data, Int32 startIndex, Int32 length)
OR
public Bitmap(Stream s, Int32 startIndex, Int32 length)
Sadly it looks like the .NET developers weren't thinking about files
like the ones my system will be creating.
Anyone know of an effective/efficient way to load Bitmaps from a binary
file?
Thanks!
Greg 8 4371 gs****@bach-simpson.com wrote:
>
A bitmap constructor like this would be great:
public Bitmap(byte[] data, Int32 startIndex, Int32 length)
OR
public Bitmap(Stream s, Int32 startIndex, Int32 length)
Sadly it looks like the .NET developers weren't thinking about files
like the ones my system will be creating.
Anyone know of an effective/efficient way to load Bitmaps from a binary
file?
Well, you can read the file using a stream reader and then use the
static FromStream method on the Bitmap class. Would that work for you?
Chris
Even better would be one that took an ArraySegment<byte>
Can you post your loop? Just want to see if you are wasting obejcts etc.
Cheers,
Greg Young
MVP - C# http://codebetter.com/blogs/gregyoung
<gs****@bach-simpson.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
Hello,
I am developing a video recording (mjpeg) system which records large
binary files. I need to read the JPEG data from the binary file and
create a bitmap object to be displayed. Unfortunately I cannot find an
efficient way to do this in C#. I need to do this at 10fps+ with 1hour+
data files.
My current approach is read a byte[] from the filestream, then create a
MemoryStream to the created byte[] and then a bitmap from the memory
stream. This seems very excessive and is quite CPU and memory
intensive.
A bitmap constructor like this would be great:
public Bitmap(byte[] data, Int32 startIndex, Int32 length)
OR
public Bitmap(Stream s, Int32 startIndex, Int32 length)
Sadly it looks like the .NET developers weren't thinking about files
like the ones my system will be creating.
Anyone know of an effective/efficient way to load Bitmaps from a binary
file?
Thanks!
Greg
No it won't because the file contains other data besides the JPEG data.
That's the problem. There is no way to create a bitmap from a portion
of a stream. I think this functionality would be useful for any object
which can be created from a stream, not just a bitmap.
Greg
Chris Dunaway wrote:
gs****@bach-simpson.com wrote:
A bitmap constructor like this would be great:
public Bitmap(byte[] data, Int32 startIndex, Int32 length)
OR
public Bitmap(Stream s, Int32 startIndex, Int32 length)
Sadly it looks like the .NET developers weren't thinking about files
like the ones my system will be creating.
Anyone know of an effective/efficient way to load Bitmaps from a binary
file?
Well, you can read the file using a stream reader and then use the
static FromStream method on the Bitmap class. Would that work for you?
Chris
Here is what I am currently doing...
// fileData is a byte[] which contains jpeg data and other data
MemoryStream ms = new (fileData);
MemoryStream imageStream;
byte[] imageBytes;
while(...)
{
// Read the image length and find the start of the image
imageBytes = new byte[imageLength];
imageStream = new MemoryStream(imageBytes);
Bitmap bMap = new Bitmap(imageStream);
}
This just seems so convoluted to me...I wish there was a better
way...grrrrr
Greg
Greg Young wrote:
Even better would be one that took an ArraySegment<byte>
Can you post your loop? Just want to see if you are wasting obejcts etc.
Cheers,
Greg Young
MVP - C# http://codebetter.com/blogs/gregyoung
<gs****@bach-simpson.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
Hello,
I am developing a video recording (mjpeg) system which records large
binary files. I need to read the JPEG data from the binary file and
create a bitmap object to be displayed. Unfortunately I cannot find an
efficient way to do this in C#. I need to do this at 10fps+ with 1hour+
data files.
My current approach is read a byte[] from the filestream, then create a
MemoryStream to the created byte[] and then a bitmap from the memory
stream. This seems very excessive and is quite CPU and memory
intensive.
A bitmap constructor like this would be great:
public Bitmap(byte[] data, Int32 startIndex, Int32 length)
OR
public Bitmap(Stream s, Int32 startIndex, Int32 length)
Sadly it looks like the .NET developers weren't thinking about files
like the ones my system will be creating.
Anyone know of an effective/efficient way to load Bitmaps from a binary
file?
Thanks!
Greg
Could you reuse a buffer isntead of creating one in your inner loop?
Also how big are these buffers?
Cheers,
Greg
<gs****@bach-simpson.comwrote in message
news:11********************@p79g2000cwp.googlegrou ps.com...
Here is what I am currently doing...
// fileData is a byte[] which contains jpeg data and other data
MemoryStream ms = new (fileData);
MemoryStream imageStream;
byte[] imageBytes;
while(...)
{
// Read the image length and find the start of the image
imageBytes = new byte[imageLength];
imageStream = new MemoryStream(imageBytes);
Bitmap bMap = new Bitmap(imageStream);
}
This just seems so convoluted to me...I wish there was a better
way...grrrrr
Greg
Greg Young wrote:
>Even better would be one that took an ArraySegment<byte>
Can you post your loop? Just want to see if you are wasting obejcts etc.
Cheers,
Greg Young MVP - C# http://codebetter.com/blogs/gregyoung <gs****@bach-simpson.comwrote in message news:11*********************@i3g2000cwc.googlegro ups.com...
Hello,
I am developing a video recording (mjpeg) system which records large
binary files. I need to read the JPEG data from the binary file and
create a bitmap object to be displayed. Unfortunately I cannot find an
efficient way to do this in C#. I need to do this at 10fps+ with 1hour+
data files.
My current approach is read a byte[] from the filestream, then create a
MemoryStream to the created byte[] and then a bitmap from the memory
stream. This seems very excessive and is quite CPU and memory
intensive.
A bitmap constructor like this would be great:
public Bitmap(byte[] data, Int32 startIndex, Int32 length)
OR
public Bitmap(Stream s, Int32 startIndex, Int32 length)
Sadly it looks like the .NET developers weren't thinking about files
like the ones my system will be creating.
Anyone know of an effective/efficient way to load Bitmaps from a binary
file?
Thanks!
Greg
i.e. you could use something like this http://msdn2.microsoft.com/en-us/library/63z365ty.aspx
this would reduce your memory usage by a huge amount.
Cheers,
Greg
<gs****@bach-simpson.comwrote in message
news:11********************@p79g2000cwp.googlegrou ps.com...
Here is what I am currently doing...
// fileData is a byte[] which contains jpeg data and other data
MemoryStream ms = new (fileData);
MemoryStream imageStream;
byte[] imageBytes;
while(...)
{
// Read the image length and find the start of the image
imageBytes = new byte[imageLength];
imageStream = new MemoryStream(imageBytes);
Bitmap bMap = new Bitmap(imageStream);
}
This just seems so convoluted to me...I wish there was a better
way...grrrrr
Greg
Greg Young wrote:
>Even better would be one that took an ArraySegment<byte>
Can you post your loop? Just want to see if you are wasting obejcts etc.
Cheers,
Greg Young MVP - C# http://codebetter.com/blogs/gregyoung <gs****@bach-simpson.comwrote in message news:11*********************@i3g2000cwc.googlegro ups.com...
Hello,
I am developing a video recording (mjpeg) system which records large
binary files. I need to read the JPEG data from the binary file and
create a bitmap object to be displayed. Unfortunately I cannot find an
efficient way to do this in C#. I need to do this at 10fps+ with 1hour+
data files.
My current approach is read a byte[] from the filestream, then create a
MemoryStream to the created byte[] and then a bitmap from the memory
stream. This seems very excessive and is quite CPU and memory
intensive.
A bitmap constructor like this would be great:
public Bitmap(byte[] data, Int32 startIndex, Int32 length)
OR
public Bitmap(Stream s, Int32 startIndex, Int32 length)
Sadly it looks like the .NET developers weren't thinking about files
like the ones my system will be creating.
Anyone know of an effective/efficient way to load Bitmaps from a binary
file?
Thanks!
Greg
Greg,
What I don't understand is why you are writing this yourself. Isn't
there a codec for this that you could use to display the file in media
player (or an embedded media player control in your program)?
It seems that you are reinventing the wheel.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
<gs****@bach-simpson.comwrote in message
news:11*********************@i3g2000cwc.googlegrou ps.com...
Hello,
I am developing a video recording (mjpeg) system which records large
binary files. I need to read the JPEG data from the binary file and
create a bitmap object to be displayed. Unfortunately I cannot find an
efficient way to do this in C#. I need to do this at 10fps+ with 1hour+
data files.
My current approach is read a byte[] from the filestream, then create a
MemoryStream to the created byte[] and then a bitmap from the memory
stream. This seems very excessive and is quite CPU and memory
intensive.
A bitmap constructor like this would be great:
public Bitmap(byte[] data, Int32 startIndex, Int32 length)
OR
public Bitmap(Stream s, Int32 startIndex, Int32 length)
Sadly it looks like the .NET developers weren't thinking about files
like the ones my system will be creating.
Anyone know of an effective/efficient way to load Bitmaps from a binary
file?
Thanks!
Greg
<gs****@bach-simpson.comwrote:
No it won't because the file contains other data besides the JPEG data.
That's the problem. There is no way to create a bitmap from a portion
of a stream. I think this functionality would be useful for any object
which can be created from a stream, not just a bitmap.
Indeed - so write a wrapper stream which will do the job for you. It
should take the start point of the virtual stream, and either the
length or the end point. You then just need to make sure that you
position the stream accordingly at the start, and delegate calls to
Read, Position etc using the offsets and the lengths.
Of course, you'd have to stipulate that once you'd been given the
stream, nothing else should manipulate it (i.e. reading the wrapped
stream would effectively cause the wrapper stream to be repositioned).
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: J. Campbell |
last post by:
OK...I'm in the process of learning C++. In my old (non-portable)
programming days, I made use of binary files a lot...not worrying
about endian issues. I'm starting to understand why C++ makes...
|
by: David Buchan |
last post by:
Hi guys,
This may be a dumb question; I'm just getting into C language here.
I wrote a program to unpack a binary file and write out the contents to
a new file as a list of unsigned integers....
|
by: Neo |
last post by:
Hello:
I am receiving a Binary File in a Request from a application. The
stream which comes to me has the boundary (Something like
"---------------------------39<WBR>0C0F3E0099" without the...
|
by: Adam J. Schaff |
last post by:
I am writing a quick program to edit a binary file that contains file paths
(amongst other things). If I look at the files in notepad, they look like:
...
|
by: John Dann |
last post by:
I'm trying to read some binary data from a file created by another
program. I know the binary file format but can't change or control the
format. The binary data is organised such that it should...
|
by: vim |
last post by:
hello everybody
Plz tell the differance between binary file and ascii
file...............
Thanks
in advance
vim
|
by: willakawill |
last post by:
I have a very large binary file saved from a vb array with 2 dimensions;
Dim arMatrix() As Byte
Dim fNum As Integer
ReDim arMatrix(7166, 17769)
'code here to store data from a database into...
|
by: rory |
last post by:
I can't seem to append a string to the end of a binary file. I'm using
the following code:
fstream outFile("test.exe", ios::in | ios::out | ios::binary |
ios::ate | ios::app)...
|
by: freeseif |
last post by:
Hi programmers,
I want read line by line a Unicode (UTF-8) text file created by Notepad, i don't want display the Unicode string in the screen, i want just read and compare the strings!.
This...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |