且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C#上传图像并保存为图像的位图大小增加

更新时间:2023-02-15 11:23:59

的目标是什么吗?你只是想上传图片?是否需要进行验证作为图像?或者,你只是想上传的文件?

What is the goal here? Are you merely trying to upload an image? Does it need to be validated as an image? Or are you just trying to upload the file?

如果上传的目的,没有任何关于验证,只是移动位,并将它们保存的文件名。只要你做到这一点...

If upload is the goal, without any regard to validation, just move the bits and save them with the name of the file. As soon as you do this ...

using (var oldImage = new Bitmap(file.InputStream))

...要转换为位图。在这里你说的是位图使用什么格式(RAW)。

... you are converting to a bitmap. Here is where you are telling the bitmap what format to use (raw).

 var format = oldImage.RawFormat;

如果您只是想移动的文件(上传),您可以运行内存流到FILESTREAM对象,并保存位。

If you merely want to move the file (upload), you can run the memory stream to a filestream object and you save the bits.

如果你想上的图像是否为空,等了几个检查,你可以试试这个页面(的 HTTP://www.$c$cproject.com/Articles/1956/NET-Image-Uploading ),但实现它仍然是把它的形象,这是不你的愿望,如果你只是想保存原样。

If you want a few checks on whether the image is empty, etc, you can try this page (http://www.codeproject.com/Articles/1956/NET-Image-Uploading), but realize it is still putting it in an image, which is not your desire if you simply want to save "as is".