FileStream的位图 [英] Bitmap with FileStream

查看:63
本文介绍了FileStream的位图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FileStream fs = new FileStream(@"image.bmp",FileMode.Open,FileAccess.Read,FileShare.Delete);

Bitmap Bmps = new Bitmap(fs);

fs.Dispose();

FileStream fs = new FileStream(@"image.bmp", FileMode.Open, FileAccess.Read, FileShare.Delete);
Bitmap Bmps = new Bitmap(fs);
fs.Dispose();

ColorMatrix CM = new ColorMatrix() ; $
CM.Matrix33 = 0.5;

ImageAttributes IA = new ImageAttributes();

IA.SetColorMatrix(CM,ColorMatrixFlag.Default,ColorAdjustType .Bitmap);

ColorMatrix CM = new ColorMatrix();
CM.Matrix33 = 0.5;
ImageAttributes IA = new ImageAttributes();
IA.SetColorMatrix(CM, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

g.DrawImage(Bmp,new Rectangle(0,0,Bmp.Width,Bmp.Height),

0,0,Bmp .Width,Bmp.Height,GraphicsUnit.Pixel,IA);

g.DrawImage(Bmp, new Rectangle(0, 0, Bmp.Width, Bmp.Height),
0, 0, Bmp.Width, Bmp.Height, GraphicsUnit.Pixel, IA);

####

上面的代码会在DrawImage()函数中抛出OutOfMemoryException。

The code above will throw OutOfMemoryException in the DrawImage() function.

但是,如果删除"fs.Dispose()",则没有问题。语句。

However, there will have no problem if I remove the "fs.Dispose()" statement.

我需要处理FileSteam,因为还有很多其他线程试图读取同一个文件。

I need to dispose off the FileSteam, because there are many other threads trying to read the same file.

我正在使用VS2008,在Windows XP SP2上。

I am using VS2008, on Windows XP SP2.

有关如何解决此问题的任何解决方案或线索?

Any solution or clue on how to address this issue?

TIA!

推荐答案

使用ReadAllBytes将文件读入MemoryStream。 从流构造theBitmap,然后处理流。
Use ReadAllBytes to read the file into a MemoryStream.  Construct theBitmap from the stream and then dispose the stream.


这篇关于FileStream的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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