1. You are prompted to download or open the file in the pop-up dialog box.
2. allow specific applications through custom HeadersProgramOpen a file
Usage: response. transmitfile ()
Routine:
Response. contenttype = "image/JPEG ";
Response. appendheader ("Content-disposition", "attachment; filename=sailbig.jpg ");
Response. transmitfile (server. mappath ("~ /Images/sailbig.jpg "));
The method used for stream transmission:
Response. binarywrite () and response. outputstream ()
Routine:
Bitmap BMP = wwwebutils. cornerimage (backcolor, color, C, radius, height, width );
Response. contenttype = "image/JPEG ";
Response. appendheader ("Content-disposition", "attenment; filename=leftcorner.jpg ");
BMP. Save (response. outputstream, imageformat. JPEG );
Reference URL for content type (MIME type:
Http://www.w3.org/TR/html4/types.html (Overview)
Http://www.iana.org/assignments/media-types/ (detail list)
Solutions to common problems:
1. An error occurs when an image is loaded from a resource file or Database BLOB field.
Error message: a generic error occurred in GDI +
Code:
Bitmap BMP = This. getglobalresourceobject ("resource", "_ bitmap") as bitmap;
Response. contenttype = "image/JPEG ";
BMP. Save (response. outputstream, imageformat. JPEG );
Response. End ();
Solution: Create an instance to receive the image content read from the resource file or Database BLOB field.
Solution code:
Bitmap BMP = This. getglobalresourceobject ("resource", "_ bitmap") as bitmap;
Bitmap temp = new Bitmap (BMP );
Response. contenttype = "image/JPEG ";
Temp. Save (response. outputstream, imageformat. JPEG );
BMP. Dispose ();
Temp. Dispose ();
Response. End ();
2. The PNG image cannot be directly stored in the output stream.
Cause: PNG is a special image format.
Solution code:
Bitmap BMP = This. getglobalresourceobject ("resource", "_ bitmap") as bitmap;
Bitmap temp = new Bitmap (BMP );
Memorystream MS = new memorystream ();
Response. contenttype = "image/PNG ";
Temp. Save (MS, system. Drawing. imaging, imageformat. PNG );
Ms. writeto (response. outputstream );
BMP. Dispose ();
Temp. Dispose ();
Response. End ();
3. Solve cache Problems
Response. contenttype = "image/PNG ";
Response. Buffer = false;
Response. Clear ();
Memorystream stream1 = new memorystream ();
// Drawpie method return an image
This. drawpie (Table1). Save (stream1, imageformat. PNG );
Response. binarywrite (stream1.toarray ());
Base. onpreinit (E );