gdi +中发生通用错误.HTML代码将图像路径保存到项目中 [英] A generic error occurred in gdi+.in HTML code save image path into the project

查看:152
本文介绍了gdi +中发生通用错误.HTML代码将图像路径保存到项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海伊..

我真的在努力解决这个错误,我尝试了所有链接,但我首先没有得到正确的答案,我想做的是,我将字节图像值保存到项目文件文件夹中,然后在浏览到jpg图像后浏览到项目文件路径中,这引发了错误,这是我的代码请帮助我

Haii..

Iam really struggling this error i tried all the links but iam not getting proper answer first i want to do i save my byte image value into project file folder i browse jpg image afer i asev into the project file path it throws the error this is my code plase help me

string converted = data.OfUploadsName.Replace(''-'', ''+'');
            converted = converted.Replace(''_'', ''/'');
            string[] spilt=converted.Split('','');
            byte[] bytes = Convert.FromBase64String(spilt[1]);
            Image image;
            using (MemoryStream ms = new MemoryStream(bytes))
            {
                image = Image.FromStream(ms);
            }
            //0.5
            var newWidth = (int)(image.Width * 1);
            var newHeight = (int)(image.Height * 1);
            var thumbnailImg = new Bitmap(newWidth, newHeight);
            var thumbGraph = Graphics.FromImage(thumbnailImg);
            thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
            thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
            thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
            var imageRectangle = new Rectangle(0, 0, newWidth, newHeight);
            thumbGraph.DrawImage(image, imageRectangle);

            thumbnailImg.Save(HttpContext.Current.Server.MapPath(@"\SurveryDAL\Images\" + "''" + id + "''+.jpg"));



我尝试过的事情:


[



What I have tried:


[^]

推荐答案

要尝试的四件事:
1)将路径更改为相对于您的站点的路径:
Four things to try:
1) Change the path to one relative to your site:
thumbnailImg.Save(HttpContext.Current.Server.MapPath(@"\SurveryDAL\Images\" + "''" + id + "''+.jpg"));

成为:

thumbnailImg.Save(HttpContext.Current.Server.MapPath(@"~\SurveryDAL\Images\" + "''" + id + "''+.jpg"));


2)删除文件名周围的引号,这些引号不是必需的,尽管它们在Windows下是合法的,但并非在所有系统上都可以.我不知道您的托管服务运行什么系统,但是最好尽可能保留字母数字文件名.
3)检查您正在生成的实际名称-将其记录下来或与调试器进行检查-准确找出要尝试写入的名称:并认真仔细检查该路径是否正确以及该文件尚不存在.由于您未在该代码中设置ID,因此可以是任何内容!
4)添加一个try ... catch块并记录并显示错误,以便您有更好的信息进行工作.


2) Remove the quotes around the filename, they aren''t needed, and while they are legal under Windows, they aren''t under all systems. I don;t know what system your hosting service runs, but it''s best to keep to alphanumerical files names where possible.
3) Check the actual name you are generating - log it or check with the debugger - to find out exactly what name you are trying to write to: and check really carefully that the path is fine and the file doesn''t exist already. Since you don''t set the id in that code, it could be anything!
4) Add a try...catch block and log and display the error so that you have better info to work on.


这篇关于gdi +中发生通用错误.HTML代码将图像路径保存到项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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