D
D
dtcDev2011-10-01 12:25:01
C++ / C#
dtcDev, 2011-10-01 12:25:01

C# working with pictures

There is an application that takes a lot of pictures from the camera. There is a task to display them on the TimeLine, as well as play the video.

Each time you capture a picture, it is saved to disk. Then the picture is loaded:

BitmapImage bmp = new BitmapImage();
bmp.BeginInit();
bmp.DecodePixelHeight = sizeHeight;
bmp.DecodePixelWidth = sizeWidth;
bmp.UriSource = new Uri(fileName, UriKind.RelativeOrAbsolute);
bmp.EndInit();

sizeHeight and sizeWidth are passed to the method and are half the size of the captured image. When processing the size of the original image 640 by 480, we get RAM consumption of 160 MB/100 images. After that, the picture is stored in the List and displayed on the TimeLine.

The question is whether it is possible to somehow optimize the work with pictures, because the task is to work with 2-3 thousand pictures.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sergeyZ, 2011-10-01
@sergeyZ

Each time you capture a picture, it is saved to disk. The image is then loaded.
But why such difficulties? Why upload it again to display it?
To the point: bitmap is not the most compact format. A sequence of bitmaps is inherently uncompressed video. A couple of seconds of such a video just takes 150-200 MB.
If I understand correctly, then in your task, the List does not save bitmaps, but links to the file? Then the memory consumption is due to the peculiarities of the work of the garbage collector in .net (memory occupied by inaccessible objects is not immediately freed) The picture should be something like this:

If you use something like List< Bitmap >, then nothing will help you. The application will gobble up all the RAM in 60 seconds, then in a couple of minutes the entire swap will hang.
Specify the task statement, explain what needs to be done.

I
icc, 2011-10-01
@icc

It is possible that the problem is in C#'s delayed memory cleanup. Try forcibly calling the System.GC.Collect() garbage collector after showing each preview.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question