Asp.net operations on image files-storage and read access

Source: Internet
Author: User

The content is referenced from:
Cainiao: high score solving: questions about SQL Server Image Storage

Http://topic.csdn.net/t/20050415/20/3940356.html

Access to image data in the database (for C #/ASP. NET)

Http://www.cnblogs.com/billsfeng/archive/2008/07/31/1257579.html

SQL Server policies and methods for storing image data

Http://www.yesky.com/20030113/1648152.shtml

How to read and write BLOB data by using ADO. Net with Visual C #. net

Http://support.microsoft.com/default.aspx? SCID = KB; en-US; 309158

1. Image Storage

A. stored in the database

In most cases, it is best to store image files and other data in the database. Because storing image data files in a database has many advantages:

Easy to manageWhen blob and other data are stored in the database, blob and table are backed up and restored together. In this way, table data and BLOB data are not synchronized, and other users accidentally delete the paths and risks of BLOB Data locations in the file system. In addition, you can insert, update, and delete blob and other data stored in the database in the same transaction. This ensures data consistency and consistency between files and databases. Another advantage is that you do not need to set security for files in the file system.

ScalabilityAlthough the file system is designed to handle a large number of objects of different sizes, the file system cannot optimize a large number of small files. In this case, the database system can be optimized.

AvailabilityDatabases have more availability than file systems. Database Replication allows you to copy, allocate, and potentially modify data in a distributed environment. When the primary system fails, log transfer provides a way to retain the standby copy of the database.

Reference: SQL Server's policy and method for storing image data

B. stored in the file system

Of course, in some cases, it is better to store images in the file system:
( 1 ) Image applicationProgramData Stream performance is required, such as real-time video reproduction.
( 2 Applications such as Microsoft photodraw or Adobe Photoshop frequently access blob, which only know how to access files.
( 3 You need to use some special functions in the NTFS file system, such as remote storage.

Reference: SQL Server's policy and method for storing image data

Suggestion: reduce the burden on database processing. You can also set up a dedicated File Server to store images and videos.

2. database storage and reading of image data

1 . Save the image file to the database. We know that the image type data in the database is "binary data". Therefore, you must convert the image file into a byte array before saving it to the database.

2. Read image data from the SQL Server database and convert it to bytes[]Or Image File

Source: Access to image data in the database (for C #/ASP. NET)

3. Custom access to image files in Asp.net

Web. config

< System . Web >   <! -- Vs debugging and IIS6 -->
< Httphandlers >
< Add Path = "*. Jpg" Verb = "*" Type = "Package name. imagehandler, DLL file"   />
< Add Path = "*. Jpeg" Verb = "*" Type = "Package name. imagehandler, DLL file"   />
< Add Path = "*. PNG" Verb = "*" Type = "Package name. imagehandler, DLL file"   />
< Add Path = "*. BMP" Verb = "*" Type = "Package name. imagehandler, DLL file"   />
</ Httphandlers >
</ System. Web >
< System . Webserver > <! -- Iis7 -->
< Handlers >
< Add Name = "Jpgmark" Path = "*. Jpg" Verb = "*" Type = "Package name. imagehandler, DLL file"   />
< Add Name = "Mark" Path = "*. Jpeg" Verb = "*" Type = "Package name. imagehandler, DLL file"   />
< Add Name = "Pngmark" Path = "*. PNG" Verb = "*" Type = "Package name. imagehandler, DLL file"   />
< Add Name = "BMP mark" Path = "*. BMP" Verb = "*" Type = "Package name. imagehandler, DLL file"   />
</ Handlers >
</ System. Webserver >


Imagehandler image scaling and watermark Effect

Http://www.blogjava.net/kiant/articles/317469.html

4. Other components

Persits aspjpeg component image watermark \ thumbnail \ image merging \ image cutting \ instance tutorial

Http://www.aspxhome.com/asp/component/200812/620614.htm

Aspjpeg feature Summary
Supports JPEG, GIF, BMP, Tiff, and PNG images. The output format is always JPEG.
Source images can be from disks, memory, or record sets (databases)
Thumbnails can be saved to disks, memory, or HTTP streams.
The following three methods are supported: nearest-neighbor, bilinear, and bicubic.
You can add images or text to images.
Supports in-picture
Supports replication, reversal, rotation, sharpening, and grayscale adjustment.
You can adjust the compression ratio to get the best output effect and size.
Extract EXIF and IPTC data from JPEG images.
CMYK-RGB Conversion
Read/write access to individual pixels of an image. (read/write access to any pixel from the image .)

5. C # How can I process GIF images? (Points are not enough)

Http://topic.csdn.net/t/20060703/11/4856635.html

Tzzzc (Leng Jian) on the eighth floor replied to 13:33:19, with a score of 0
To: knight94 (yuweng)
Graphics myimg = graphics. fromimage (zoomimg); // create graphics
In the last sentence, a problem occurs (when processing GIF images, the system prompts that graphics cannot be created from images with indexed pixel format). The old prompt is: a graphics object cannot be created from

9 Floor knight94 (yuweng) reply to 13:41:34 score 0
Do not use GIF images to directly generate graphics objects,

Process:
1. Break down GIF files into PNG or JPG file groups;
2. process each PNG or JPG file;
3. Combine the processed PNG or JPG file group into a GIF file.

6. How to Solve the common error of GDI + when ASP. NET outputs PNG Images
Detailed source reference: http://www.jb51.net/article/17063.htm

response. contenttype = "image/PNG";
using (memorystream MS = new memorystream ()
{< br> IMG. save (MS, chartformat. PNG);
response. outputstream. write (Ms. getbuffer (), 0, (INT) ms. length);
}< P>

you can enter a PNG image.
This is because the stream response. outputstream cannot be read back, that is, its canseek attribute is false. When a PNG image is generated, it is not like jpeg. It is not streaming. If it has already been written, it is no longer necessary. Instead, it is necessary to constantly write structural data back. However, the response stream cannot go back to seek, so it cannot be used directly. Change it to a memorystream that can be seek. convert it into a PNG image and then output it to the response stream.

Related Article

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.