[Original] how to process images in ASP. NET web applications

Source: Internet
Author: User

 

Regular, direct analysisCode

First, create a table. The field type is image.

Normally, you will find that there is no way to store the image, because the length is 50 and cannot be changed. A single image is usually more than 1000

The length of the image data type is 16. When I save a graph, the maximum size of the graph can be about 30 kb. A large graph cannot be saved at all. I want to change its length, but it cannot.
Run the following statement:

Sp_tableoption n 'mytable', 'text in row', and '123456' are effective only when this image type data is executed.

Second, convert the file to a byte array of binary data.

Convert files into binary data
Public static byte [] picturefiletobyte (string picfilepath)
{
Filestream FS = new filestream (picfilepath, filemode. Open, fileaccess. Read );
Byte [] bytephoto = new byte [fs. Length];
FS. Read (bytephoto, 0, (INT) fs. Length );
FS. Close ();
Return bytephoto;
}

 

The image is saved to the database.

 

Read

Create an image control, image. imageurl = image. aspx? Id = 2002

2002 is the row ID of the table storing images in the database,

Image. aspx

Protected void page_load (Object sender, eventargs E)
{
String guid = request. querystring ["ID"];
If (guid! = NULL)
{
Response. clearcontent ();
Response. contenttype = "image/JPEG ";
Byte [] DATA = utility. Picture (guid); read binary data bytes
Response. binarywrite (byte []) data );
}

}

 

In this way, you can.

If you have any questions, please leave a message.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.