如何使用AForge减小图像大小并减少每秒图像的数量 [英] How to decrease size of image and descrease the amount of images per second using AForge

查看:171
本文介绍了如何使用AForge减小图像大小并减少每秒图像的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我尝试使用AForge从网络摄像头将图像保存在磁盘上。但是图像在磁盘上占用了大量的图像并且图像数量很高。我想减少图像的大小并减少每秒(分钟)的图像数量。但是我不知道该怎么做



主要代码:

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:

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++;

        }



我尝试使用DesiredFrameRate,但它不适用于Framework 2.2.5。此外,我无法更改VideoCapabilities中的数据,例如bitCount,FrameRate等,因为此字段仅用于读取。对不起我的英语。希望你能帮助我减少图像的大小并减少每秒(分钟)的图像数量:)


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):)

推荐答案

public static System.Drawing.Image Resize (System.Drawing.Image image,int width,int height,RotateFlipType rotateFlipType)

{

//克隆Image实例,因为我们不想调整大小原始图像实例

// var rotateImage = image.Clone()as System.Drawing.Image;

//rotatedImage.RotateFlip(rotateFlipType);

// var newSize = CalculateResizedDimensions(rotateImage,width,height);



var newSize = CalculateResizedDimensions(图片,宽度,高度);



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

resizedImage.SetResolution(72,72);



使用(var graphics = Graphics.FromImage(resizedIm年龄))

{

//设置参数以创建高质量缩略图

graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

graphics.SmoothingMode = SmoothingMode.AntiAlias;

graphics.CompositingQuality = CompositingQuality.HighQuality;

graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;



//使用图像属性,以便在调整大小后删除图像周围的黑/灰边框

using(var attribute = new ImageAttributes())

{

attribute.SetWrapMode(WrapMode.Tile);



//将调整后的图像绘制到位图

graphics.DrawImage(image,new Rectangle(new Point(0,0),newSize),0,0,image.Width,image.Height,GraphicsUnit.Pixel,attribute);

}

}

image.Dispose();

返回resizedImage;

}



我认为这个功能可以帮助你..
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..


这篇关于如何使用AForge减小图像大小并减少每秒图像的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆