Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So, i try to save image on disk from web camera using AForge. But the image takes a lot of size on disk and amount of images is high. I want to descrease the size of images and descrease the amount of images per second(minute). But i don't know how to do this

Main code:
C#
public void button1_Click(object sender, EventArgs e)
        {
            FinalVideo = new VideoCaptureDevice(VidoeCaptureDevices[comboBox1.SelectedIndex].MonikerString);
            FinalVideo.VideoResolution = FinalVideo.VideoCapabilities[2];
            FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
            FinalVideo.Start();
        }
        void FinalVideo_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap video = (Bitmap)eventArgs.Frame.Clone();
            video.Save("C:\\image\\file"+i+".bmp");
            pictureBox1.Image = video;
            i++;

        }

I was tryed to use DesiredFrameRate but it doesn't works on Framework 2.2.5. Also i can't change the data from VideoCapabilities, for example bitCount, FrameRate etc, because this fields only for read. PS sorry for my English. Hope that you can help me to descrease the size of images and descrease the amount of images per second(minute):)
Posted

1 solution

public static System.Drawing.Image Resize(System.Drawing.Image image, int width, int height, RotateFlipType rotateFlipType)
{
// clone the Image instance, since we don't want to resize the original Image instance
//var rotatedImage = image.Clone() as System.Drawing.Image;
//rotatedImage.RotateFlip(rotateFlipType);
//var newSize = CalculateResizedDimensions(rotatedImage, width, height);

var newSize = CalculateResizedDimensions(image, width, height);

var resizedImage = new Bitmap(newSize.Width, newSize.Height, PixelFormat.Format32bppArgb);
resizedImage.SetResolution(72, 72);

using (var graphics = Graphics.FromImage(resizedImage))
{
// set parameters to create a high-quality thumbnail
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

// use an image attribute in order to remove the black/gray border around image after resize
using (var attribute = new ImageAttributes())
{
attribute.SetWrapMode(WrapMode.Tile);

// draws the resized image to the bitmap
graphics.DrawImage(image, new Rectangle(new Point(0, 0), newSize), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attribute);
}
}
image.Dispose();
return resizedImage;
}

I think this function will help you..
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900