C# 从ASP.NET网站下载生成的位图图像
我正在从文本和asp.net网站上的现有图像动态生成图像 代码如下:C# 从ASP.NET网站下载生成的位图图像,c#,asp.net,image,bitmap,C#,Asp.net,Image,Bitmap,我正在从文本和asp.net网站上的现有图像动态生成图像 代码如下: string barcode = Request.QueryString["BarCode"]; int w = barcode.Length * 40; // Create a bitmap object of the width that we calculated and height of 100 Bitmap oBitmap = new Bitmap(w, 50); // then create a Graphi
string barcode = Request.QueryString["BarCode"];
int w = barcode.Length * 40;
// Create a bitmap object of the width that we calculated and height of 100
Bitmap oBitmap = new Bitmap(w, 50);
// then create a Graphic object for the bitmap we just created.
Graphics oGraphics = Graphics.FromImage(oBitmap);
// Now create a Font object for the Barcode Font
// (in this case the IDAutomationHC39M) of 18 point size
Font oFont = new Font("BarcodeFont", 12);
// Let's create the Point and Brushes for the barcode
PointF oPoint = new PointF(2f, 2f);
SolidBrush oBrushWrite = new SolidBrush(Color.Black);
SolidBrush oBrush = new SolidBrush(Color.White);
// Now lets create the actual barcode image
// with a rectangle filled with white color
oGraphics.FillRectangle(oBrush, 0, 0, w, 100);
// We have to put prefix and sufix of an asterisk (*),
// in order to be a valid barcode
oGraphics.DrawString(barcode, oFont, oBrushWrite, oPoint);
// Then we send the Graphics with the actual barcode
Response.ContentType = "image/png";
oBitmap.Save(Response.OutputStream, ImageFormat.Png);
正如您所见,位图在回发后保存并显示在aspx页面上。我想做的是当用户点击按钮1,然后图像生成和浏览器下载窗口弹出,而不保存在服务器上或显示在页面上。如何做到这一点?请帮助我。您应该更新您的回复,如下所示:
Response.ContentType = "image/jpeg";
Response.AppendHeader("Content-Disposition","attachment; filename=downloadedFile.JPG");
Response.TransmitFile( @"c:/my documents/images/file.xxx" );
Response.End();
有关详细信息:我可以让用户选择文件目的地吗?@Mira是的,您可以检查给定的链接找不到路径的一部分。您尝试了吗?TransmitFile(Server.MapPath(“~/images/sailbig.jpg”)
~/images/sailbig.jpg
是您的图像路径