c#将图片文件保存到ram [英] c# save a picture file to ram

查看:146
本文介绍了c#将图片文件保存到ram的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个图像处理程序,我需要从视频中保存一些图片并对它们进行一些处理。
当处理1张图片时,它并不需要时间,
但是当我处理100张图片时它会产生差异
我将文件保存到我的硬盘上,那就是为什么需要时间
,我正在使用的函数是一个现成的函数,它只接受(文件名)
函数真的很复杂所以我不能建立我自己的函数(如果那是你在想什么)

I am developing a program for image processing, and I need to save some pictures from a video and do some processing on them. When dealing with 1 picture it doesn't really take time, But when I'm dealing with 100 pictures it makes difference I'm saving the files to my hard disk, and that's why it takes time the thing is, the function I'm using is a ready made function and it only accepts (file name) the function is really complicated so i cannot build my own function ( if that's what you are thinking )

我现在正在考虑两件事,并希望得到你的意见:

I'm thinking of 2 things right now and would like to have your opinions about them:


  1. 更改函数的输入,但如何?有没有办法将此输入从(文件名)更改为包含这些图片的数组?


  2. 将文件保存到ram。但如何通过名称将文件保存到ram,并能够在函数中将它们用作(文件名)?

我很感激你的帮助,非常感谢

I appreciate your help , thanks so much

这是我的代码,但我仍有问题:

this is my code but i still have problems:

            Capture video = new Capture("c:\\5.avi");
            Image<Bgr, Byte> Imageframe ;

            Dictionary<string, MemoryStream> dict = new Dictionary<string, MemoryStream>();

                Imageframe = video.QueryFrame();
                Bitmap bmp = Imageframe.ToBitmap();
                dict.Add("mypicture.png", new MemoryStream());
                bmp.Save(dict["mypicture.png"],imageformat.png);    

上下文中说imageformat不存在

its saying imageformat does not exist in the context

这是我使用的函数:

Image<Bgr, byte> result;
                 result = DrawMatches.Draw("box.png", "box_in_scene.png", out matchTime,i); 


推荐答案

你可以保存到RAM(最宽松的感官) )使用 MemoryStream 。如果你想给它们命名,可以使用 Dictionary< string,MemoryStream> ,例如:

You could save to RAM (in the loosest of senses) using a MemoryStream. If you wanted to name them you could use a Dictionary<string,MemoryStream>, such as:

Dictionary<string,MemoryStream> dict = new Dictionary<string,MemoryStream>();

dict.Add("mypicture.png",new MemoryStream());

image.Save(dict["mypicture.png"]);

但是你需要为这些流编写清理代码,这并没有考虑到最终你可以用完所有的物理RAM,然后开始进入分页文件,无论如何都是基于磁盘。

However you'll need to write cleanup code for these streams and this doesn't take into account that eventually you could use up all the physical RAM and then start going into the paging file, which is disk based anyhow.

顺便说一句,如果这是在服务器上你控制并且您不会向最终用户发布此软件,您可以使用物理RAM作为Windows可用的实际磁盘的RAM磁盘驱动器(仅限Google)。然后你可以加载/保存到那个。

As an aside, if this is on a server you control and you're not releasing this software to end users you could get a RAM disk drive (plenty around just Google) that uses physical RAM as an actual disk available to Windows. Then you could just load/save to that.

非常非常粗糙 EmguCv变种:

Very very rough EmguCv variant:

// Global dictionary of memory streams
Dictionary<string,MemoryStream> dict = new Dictionary<string,MemoryStream>();

// Add image memory stream to dictionary
dict.Add("mypicture.png",new MemoryStream());

// Get bitmap from EmguCv
Bitmap bmp = image.ToBitmap();

// Save bitmap to image memory stream
bmp.Save(dict["mypicture.png"],ImageFormat.Png);

// Get bitmap from memory stream
dict["mypicture.png"].Seek(0,SeekOrigin.Begin);
Bitmap new_bmp = Image.FromStream(dict["mypicture.png"]);

// Convert bitmap to EmguCv image
Image<Bgr,Byte> new_img = new Image<Bgr,Byte>(new_bmp);

这篇关于c#将图片文件保存到ram的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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