如何在文件夹中保存图像. [英] How to save image in folder.
本文介绍了如何在文件夹中保存图像.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将bytearray []转换为System.drawing.image,这工作正常.但是如何将这个图像保存到本地目录中.
如果我给_objImage.Save(path,_objImage.RawFormat);这会导致错误.
"GDI +中的错误"
给我一个解决办法.
对不起,我听不懂.
这是我的代码,用于将base64代码转换为图像.
hi ,
I am converting bytearray[] to System.drawing.image this is working fine. But how can i save this image into local directory.
if I give _objImage.Save(path,_objImage.RawFormat); this give an error.
"Error in GDI+"
Give me a solution.
Sorry I can''t understand.
This is my code to convert base64 code into image.
public static Image Base64ToImage(string base64String)
{
byte[] imageBytes = Convert.FromBase64String(base64String);
Image image;
using (MemoryStream inStream = new MemoryStream())
{
inStream.Write(imageBytes, 0, imageBytes.Length);
image = Bitmap.FromStream(inStream);
// image.Save(inStream, System.Drawing.Imaging.ImageFormat.Png);
image.Save(inStream, image.RawFormat);
}
return image;
}
现在我想将此图像保存到本地目录中,我该怎么做.
如果我使用
Now i want save this image into local directory how can i do this.
if i use
Image _ObjImage = Base64ToImage(Img);
DirectoryInfo dir = new DirectoryInfo(PATH + @"EndUsersUI\UploadedPic\" + id +"\\");
_ObjImage.Save(dir + smallpicname, _ObjImage.RawFormat);
这给了我一个错误.
This is giving me an error.
推荐答案
现在服务器中已有JPG文件.如果要保存在客户端计算机中,则必须进行传输.这是代码:-
Now you have JPG file in server. If you want to save in client machine then you have to transmit that. Here is code :-
Response.ContentType = "image/jpeg";
Response.AppendHeader("Content-Disposition", "attachment; filename=Image.jpg");
Response.TransmitFile(Server.MapPath("Image.jpg"));
Response.End();
引用此内容
http://www.aspnettutorials.com/tutorials/database/store-img- bins-asp4-cs.aspx [ ^ ]
Refer this
http://www.aspnettutorials.com/tutorials/database/store-img-bins-asp4-cs.aspx[^]
最后我解决了.
答案是将ByteArray []转换为Image中没有的Bitmap之后,您可以轻松地将图像存储到任何文件夹中,或者可以通过Drawing类的resize方法进行裁剪.
Finally i have solved.
and the answer is Convert ByteArray[] to Bitmap not in Image after that u can easily store your image into any folder or u can crop this through resize method of Drawing class.
这篇关于如何在文件夹中保存图像.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文