Export (0) Print
Expand All

ShowImage 

Demonstrates how to convert, store, and retrieve images. Allows the user to upload images that the server will attempt to convert to PNG format. If successful, the PNG format data is added to a database. Images in the database can be downloaded using a URL that contains the ID of the image as a parameter in the query string.

  • IIS

  • SQL Server

  1. Create a SQL server database and run the ShowImage.sql SQL script to create the necessary tables and stored procedures.

  2. Before building and deploying the application, double-click ShowImage.udl and configure the data link properties to point to the database you just set up.

    If the database connection uses Windows authentication, make sure that the IUSR_Machine account has read-write access to the database. See ATL Server Security for information about the accounts used by a typical ATL Server application running in IIS.

    If the database connection uses SQL authentication, make sure that the security information is persisted.

  3. After building and deploying the application, change the NTFS security settings on the UDL file that was deployed to the same location as ShowImage.dll to allow read access by the IUSR_Machine account.

Use a browser to view ShowImage.srf and use the form linked to from that page to send some image files to the server. The server will attempt to convert the files to PNG format and add the image data to the database. The response will indicate which files were received by the server, which files were images, which could be converted to PNG format, and which of those could be added to the database. Any images added to the database will be displayed as part of the page.

The server loops through the files sent to the server and loads each of them into a CImage object. If the file could be loaded successfully, the server generates a temporary file name and tries to save the image to that file name in PNG format. If that is successful, the server loads the file into an object that exposes the data through the IWriteStream interface and hooks that up to an OLE DB accessor. The server then calls a stored procedure using that accessor to add the image to the database along with information such as its width, height, and bits per pixel.

Each image added to the database causes an IMG element to be added to the response. The SRC attribute of the IMG is a URL to this page. The presence of a query string indicates that the server should send back image data retrieved from the database rather than an HTML page. In this example, the query string just contains the ID of the database record holding the image. This ID is used as a parameter to a stored procedure that returns the image data that is then written to the client.

Demonstrates

Community Additions

ADD
Show:
© 2015 Microsoft