0

I am trying to create an application to display 8/16bit grayscale video. Currently, I create a BMP bitmap as RGB48 from frames, and simply assign

pictureBox.Image = bmp

This requires to create three redundant channels to make an RGB image look like grayscale (the grayscale image formats do not seem to work). This approach works on my fast computer, but slower computers can not keep up. So, I was hoping that someone could advise a better way of how to display images fast and efficient.

In my previous question, I was advised to display images on a panel using onPaint event, instead of picturebox. However, I still did not figure out how to do it.

  1. Is there a way to avoid creating three color channel for RGB if it is to be displayed as a grayscale?
  2. If I place a panel component on the current form, how to create an Onpaint event so the panel displays the image?

The general functioning of my program is as follows: One thread receives the image data and the other thread collects this data into a larger byte array. As soon as the larger array contains enough data for a full frame, I display the image.

Community
  • 1
  • 1
Nazar
  • 820
  • 5
  • 13
  • 36
  • 1
    2 - You have to create a subclass of Panel and override its OnPaint. – Lorek Oct 28 '15 at 20:57
  • 1 - How do you get the frames? Are you using DirectShow? If so, you might be able to apply a filter to your graph that could utilize the GPU to convert the images to gray scale. Again, how do you get the frames? – Lorek Oct 28 '15 at 21:04
  • @Lorek The raw pixel data is streamed via USB. So, the starting point where I own the data is the global array to which I collect data. – Nazar Oct 28 '15 at 21:07
  • Can you provide a sample image? And can you provide the code you are currently using to convert the bytes to a bitmap? Have you run a profiler on your code to see what is costing the most time? – Lorek Oct 28 '15 at 21:13
  • you can also use a double buffering technique where your loading the images in another image box as well and just unhiding that image when you need it – johnny 5 Oct 28 '15 at 21:27
  • [You might want to have a look at this answer. It explains what you can do to make the most of GDI+..](http://stackoverflow.com/a/11025428/1277156) – Measurity Oct 29 '15 at 10:08
  • @Lorek The image is just a collection of 16bit values 640x480 frame. It is a raw data - no video standard. Look at the accepted answer [here](http://stackoverflow.com/questions/32290631/how-to-display-raw-data-as-an-image-visual-studio-c) - I use this code. I do not know how to perform profiling, however, since I do not do anything else with the program but display images, I would expect that to be the limiting factor. Actually, after increasing transfer buffer sizes from USB, the program works ok. Well, I would still be interested to re-write it the proper way. – Nazar Oct 29 '15 at 11:58
  • That answer converts from grayscale to RGB48. I thought you wanted to go the opposite way. If you provide code I will be much more helpful. What is your source format? What is your output format? Check out dotTrace for profiling. – Lorek Oct 29 '15 at 12:07
  • @Lorek That is the answer to my previous question. My input data is for grayscale. However, the *PixelFormat.Format16bppGrayScale* does not work, so I had to create *PixelFormat.Format48bppRgb* making it look like grayscale. The code is exactly like in that answer, except I do not have to fill the buffer with random values. – Nazar Oct 29 '15 at 12:16

0 Answers0