I need to write an app to playback a DICOM multiframe image. Each frame is stored in JPEG format. All the frames are stored consecutively in one file. Right now, I read out each frame data and pass it to the following routine to construct a Bitmap for display:
Bitmap CreateBitmap(byte[] pixelBuffer, int frameSize)
{
Bitmap image = null;
try
{
long startTicks = DateTime.Now.Ticks;
MemoryStream pixelStream = new MemoryStream(pixelBuffer, 0, frameSize);
image = new Bitmap(pixelStream);
loadTime = DateTime.Now.Ticks - startTicks;
}
catch (Exception ex)
{
Log.LogException(ex);
}
return image;
}
During the test, everything works fine except that the performance in the above routine is not optimal. For the 800x600 frame size, the time it takes in this routine is either 0msec and 15msec (I don't know why). For the 1024x768 frame size, the time it takes is either 15msec or 31msec. My goal is to stream the image data in and playback the image (1024x768 version) in 60Hz without dropping a frame. That suggests I have to decompress the JPEG frame within 15msec constantly. So my question is what's the better way to do this?
To unzip a single file or folder, open the zipped folder, then drag the file or folder from the zipped folder to a new location. To unzip all the contents of the zipped folder, press and hold (or right-click) the folder, select Extract All, and then follow the instructions.
The JPEG decoder takes a JPEG image and converts it to a (uncompressed) bitmap using a decoding method called the baseline decoding process. A short introduction to the JPEG decoding process can be found in chapter 2 and appendix of the report "Design and implementation of a JPEG decoder" by Sander Stuijk.
It's 0 msec or 15 msec because your timer lacks resolution. Use QueryPerformanceCounter
to get accurate times.
The WPF JPEG decoder (System.Windows.Media.Imaging
) is faster than the GDI+ decoder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With