如何加载图像与位图相对路​​径 [英] how to load image with relative path in bitmap

查看:119
本文介绍了如何加载图像与位图相对路​​径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要上传图片INT从asp.net的位图对象,图像位置在

i want to upload image int the bitmap object from asp.net, the image is location under

/uploadedimages/sampleimage.jpg

每当我用下面的code加载位图图像,我得到错误说参数不是有效的。

whenever i use below code to load image in bitmap, i gets error saying Parameter not valid.

Bitmap b = new Bitmap("/uploadedimages/sampleimage.jpg") // this path is coming from database holded in variable

我试图替代路径斜杠为\\仍然不起作用。

i tried to replace the slashes in path to "\" still that does not work.

谁能告诉我什么可能是错误的原因和可能的解决方案。

can anyone tell me what could be the reason for the error and the possible resolution.

推荐答案

如果 uploadedimages 目录是在的App_Data 文件夹,那么你应该追加的App_Data 绝对路径的路径:

if uploadedimages directory is in your App_Data folder then you should append the App_Data absolute path to your path:

Bitmap b = new Bitmap(Path.Combine(Server.MapPath("~/App_Data"), "/uploadedimages/sampleimage.jpg"));

这篇关于如何加载图像与位图相对路​​径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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