English 中文(简体)
ASP.NET C#处理图像
原标题:ASP.NET C# Handling an Image

类似我的其他问题之一, 但我需要澄清。

我有一个网络应用程序, 多个用户将同时使用。 在应用程序中, 一个图像, 在一个应用程序文件夹中, 将会像下面一样被绘制, 保存下来, 然后添加到页面上的图像控制中 。

Bitmap image = new Bitmap(Server.MapPath("~") + "/Assets/img/timegrid.jpg");
Graphics graphics = Graphics.FromImage(image);
Pen p = new Pen(Color.Blue, 5); 
//draw on image
graphics.DrawLine(p, aPoint, bPoint); 

//save new image
image.Save(Server.MapPath("~") + "/Assets/img/newtimegrid.jpg");
imgGrid.ImageUrl = "~/Assets/img/newtimegrid.jpg";

每个用户的新图像都会看起来不同。 然而, 我担心用户A会看到用户Bs newtimegrid.jpg, 而不是他自己的。 因为每个用户都在保存到同一个文件名。 我听说过使用通用的图像处理器, 我在这里读过一些解决方案, 但我仍然不明白如何使用它, 或者如果我做了它, 或者如何使用它, 或者这是否甚至解决了我的问题。 任何帮助都会受到欢迎 。

最佳回答

我建议您在会话中保留用户ID, 并使用此 ID 路径, 以独特的方式识别每个用户图像路径的图像路径 。

您可以首先检查用户路径是否已经存在 。

string strDirPath = Server.MapPath("~") + "/Assets/img/ + Session["UserID"].ToString();

if(Directory.Exists(strDirPath))
{
     Bitmap image = new Bitmap(strDirPath + "\" + timegrid.jpg");
     //your code here
}
else
{
     DirectoryInfo CreateDirectory(strDirPath);
     Bitmap image = new Bitmap(strDirPath + "\" + timegrid.jpg");
     //your code here
}
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签