문제

I am using a C#, Winforms application with the Aforge library to pull video from a USB camera and manipulate that video.

I am doing it by using the new frame event handler and posting that image into a picturebox. So far, it has worked well and done what I want.

However, I recently found out I need to add software zoom to the application. My solution was to increase the size of the overall image and then grab a section of the new, larger image, that fit the measurements I needed. This is done on every new frame.

     int imageTopY;
     int imageTopX;
     Rectangle rect;

     bitmap = new Bitmap(bitmap, new Size(bitmap.Width * zoomTrackBar.Value, 
                                          bitmap.Height * zoomTrackBar.Value));

     imageTopY = ((bitmap.Height - height) / 2);
     imageTopX = ((bitmap.Width - width) / 2);

     if (imageTopY != 0 && imageTopX != 0)
             rect = new Rectangle(imageTopX, imageTopY, width, height);
     else
             rect = new Rectangle(0, 0, width, height);

      bitmap = (Bitmap)bitmap.Clone(rect, bitmap.PixelFormat)

This also does what I need it to. HOWEVER, it is not at all efficient. When the zoome level hits 3, the video becomes exceptionally laggy. There is a latency of 1-2 seconds between the video feed and what is going on. I can get up and do a little dance, and by the time I sit down in my chair, the me in the video starts doing a little dance :-P

Any suggestions on a better way to achieve what I am trying to do? Maybe something more streamlined?

도움이 되었습니까?

해결책

Instead of enlarging the overall image, cut out the section you wish you zoom in to and fill the window with that image. This way, you are always having a max image size of the video window and not enlarging the overall image beyond the window's constraints.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top