TECH REP SHANKY_2_ by nagaprasad333


									                         A TECHNICAL SEMINAR REPORT


A technical seminar report submitted in Partial Fulfillment of the Requirements for the Award of
                                         the degree of

                                 Bachelor of Technology
                                Information Technology
                                         Submitted by
                                 T.SHASHANK REDDY

                                (ROLL NO: 07B81A1253)
                                  CVR College of engineering


                        CVR COLLEGE OF ENGINEERING

                Mangalpally (v), Ibrahimpatnam (M), R.R.Dist-501510
                            (Affiliated to JNTU, Hyderabad)


       This   is to    certify that    the Technical     seminar entitled “DISPLAYING AND
       CUSTOMIZING IMAGES ON DATABASE” has been completed under our guidance and
       supervision, in partial fulfillment of the requirements of the award of Degree to CVR
       COLLEGE OF ENGINEERING, is a record of bonafide work carried out by

                                T.SHASHANK REDDY(07B81A1253)

    The results embodied in this Technical seminar have not yet been submitted to any other
    University or institutions for the award of any degree.

                                    Under the esteemed guidance of

Mr. N. Nagarjuna                                                Prof. R. Seetharamaiah

Assistant Professor, IT                                         Head of the department, IT

CVR College of Engineering                                      CVR College of Engineering


    The satisfaction that accompanies the successful completion of any task would be
incomplete without the mention of the people who made it possible and whose encouragement
and guidance has been a source of inspiration throughout the submission of the technical report.

   I feel a great pleasure to express my deep sense of gratitude towards CVR College of
Engineering, for lending their valuable guidance in completing this technical report.


 This is to declare that the dissertation entitled “DISPLAYING AND CUSTOMIZING
 IMAGES ON DATABASE” that is being submitted by in partial fulfillment for the award of
 the Degree of Bachelor of Technology in IT branch to the Jawaharlal Nehru Technological
 University is a record of Bonafide work carried out by her under our guidance and supervision. The
 results embodied in this Technical seminar report have not been submitted to any other University or
 Institute for the award of any degree or diploma.


                                    T.SHASHANK REDDY (07B81A1253)

____________________________                                  ____________________________

      SIGNATURE OF THE                                              SIGNATURE OF THE

       INTERNAL GUIDE                                           HEAD OF THE DEPARTMENT


Sometimes you need to store images in a database instead of as physical files. The obvious

implication is that the image is stored on the file system somewhere or at a remote location. In

order to provide your application with cool pictures you can employ two techniques (at least).

One of them is that you can save the pictures in a folder and store the path to each one in a

database or configuration file. The other one is to store the entire file into a database, along with

its file name. The problem of uploading files to a database is not that difficult. You have to use,

on the server, a certain data type when creating the table. This data type has to be capable of

storing large amounts of binary data.Since we have huge amounts of data in databse it doesn’t

matter about the size of the image. Even it is easy to store images of 3D images without any huge

efforts.Here we are going to discuss about how to store images in a database and also how also

the methods displaying and customizing them in the database. The solution presented here uses

an HttpContext to display an image. Another part of the solution strips the OLE header out of the

images in the Northwind database's categories table, and the final bit of the example

demonstrates how to customize the image by creating a GDI+ object and drawing on the

image.Here we use the softwares like Apache and MySQL for storing and customizing the data.

Here we also use the concept of JDBC-ODBC connectivity for connecting to any of the database

for storing and retrieving and information.

                    TABLE OF CONTENTS

1. INTRODUCTION…………………………………………………………….… 07
  1.1 Use of storing data in databases…………………………………………...07
  1.2   Storage Structures…………………………………………………………08

  1.3 How to store images……………………………………………………….09
  2.1   Sample code for displaying image in database……………………………11
  2.2   Removing the old header………………………………………………….16
4. ADVANTAGES……………………………………………………………….....17
5. CONCLUSION………………………………………………………….……..…18
6. REFERENCES…………………………………………………………..……….19

                                    1. INTRODUCTION

Disk space is cheap, so it is better preferable for storing images in the database whenever
possible. Storing the images in the database makes them portable with the database, less likely to
be tampered with, and the images get backed up when the database gets backed. The only
challenge is getting the image from the database column into a control. It is possible to store
images in a database using a number of third party tools or a custom built component. Once you
have the images stored in your database, however, displaying them requires the use of a simple
HTTP pages. . The problem of uploading files to a database is not that difficult. You have to use,
on the server, a certain data type when creating the table. This data type has to be capable of
storing large amounts of binary data.


Databases help in storing large amounts in any of the forms. Even we lose the data in our
systems or in any other file systems it is very difficult to lose data that from the databases.
A database is a system intended to organize, store, and retrieve large amounts of data easily. It
consists of an organized collection of data for one or more uses, typically in digital form. One
way of classifying databases involves the type of their contents, for example: bibliographic,
document-text, statistical. Digital databases are managed using database management systems,
which store database contents, allowing data creation and maintenance, and search and other
access. Most DBMS provide some form of support for transactions, which allow multiple data
items to be updated in a consistent fashion, such that updates that are part of a transaction
succeed or fail in unison. The so-called ACID rules, summarized here, characterize this behavior:

1. Atomicity: Either all the data changes in a transaction must happen, or none of them. The
transaction must be completed, or else it must be undone (rolled back).

2. Consistency: Every transaction must preserve the declared consistency rules for the database.

3. Isolation: Two concurrent transactions cannot interfere with one another. Intermediate results
within one transaction must remain invisible to other transactions. The most extreme form of
isolation is serializability, meaning that transactions that take place concurrently could instead be
performed in some series, without affecting the ultimate result.

4. Durability: Completed transactions cannot be aborted later or their results discarded. They
must persist through (for instance) DBMS restarts.

In practice, many DBMSs allow the selective relaxation of these rules to balance perfect
behavior with optimum performance.

Some of the efficient uses of using the databases are:

1. Providing knowledgeable customer service.

2. Make products and services tailored to customer preferences.

3. Develop individualized, targeted marketing programs.

4. Conduct one-on-one dialogs with each customer.

5. Enlisting loyal customers in referral programs.

6. Classify customers by interests and profitability so as to give special attention to those most
likely to build the bottom line.

7. Devise effective marketing programs to new prospects.


Databases may store relational tables/indexes in memory or on hard disk in one of many forms:

1. Ordered/unordered flat files


3. Heaps

4. Hash buckets

5. Logically-blocked files

6. Fractal Tree indexes

7. B+ trees

The most commonly used are B+ trees and ISAM.

Object databases use a range of storage mechanisms. Some use virtupal memory-mapped files to
make the native language (C++, Java etc.) objects persistent. This can be highly efficient but it
can make multi-language access more difficult. Others disassemble objects into fixed- and
varying-length components that are then clustered in fixed sized blocks on disk and reassembled
into the appropriate format on either the client or server address space. Another popular
technique involves storing the objects in tuples (much like a relational database) which the
database server then reassembles into objects for the client.

Other techniques include clustering by category (such as grouping data by month, or location),
storing pre-computed query results, known as materialized views, partitioning data by range
(e.g., a data range) or by hash.

Memory management and storage topology can be important design choices for database
designers as well. Just as normalization is used to reduce storage requirements and improve
database designs, conversely denormalization is often used to reduce join complexity and reduce
query execution time.


Most of the web applications have a lot of images used in it. These images are usually stored in a
web server folder and they are accessed by giving the relative path to the file with respect to the
root folder of the website. .Net being the platform for distributed application now, ASP.Net can
be used to store images that are small to be stored in a database like SQL Server 2000 and later
versions. For this purpose the SQL Server database provides a data type called “image” which is
used to store images in the database.

To access these images stored in the database we will be using the ADO.Net classes. To find out
how to insert and retrieve an image in to the SQL Server database, you can create an .aspx page
which can have an HTMLInputFile control which is used to select the image file that is to be
saved in the database.

You can also create a textbox control in which you can add the image name or some comment or
an image id for the image saved. Use a button control to upload the image to the database.
Namespaces like System.Data.SqlClient, System.Drawing, System.Data, System.IO, and
System.Drawing.Imaging are used in this task. You can use these algorithms and take advantage
of the “image” data type available in the SQLServer 2000 database to store small images that
correspond to a particular record in the table of the database. This method of storing avoids the
tedious task of tracking the path of the web folder if the images are stored in a web folder.

The following describes the method of storing data in database:

INSERT INTO DBFiles(fname, [file])
SELECT 'Reporting-Services-2008-enriched-visualization-gadgets.jpg', * FROM
  BULK N'C:\Reporting-Services-2008-enriched-visualization-gadgets.jpg',
) rs;
INSERT INTO DBFiles(fname, [file])
SELECT 'what-is-new-with-SQL-Server-2008.jpg', * FROM OPENROWSET(
  BULK N'C:\what-is-new-with-SQL-Server-2008.jpg',
) rs;

Displaying an image from a database works when you write the image's bytes to the response
stream; that is, you stuff the image bytes into the data going back to the client. If you just write
the image bytes to the response stream of the page the image will be on then you inadvertently
write over all of the other bytes and only get the image. The added element needed to get the
image and the other data to show up together is to write the picture to a second page (or
UserControl's) stream and embed that UserControl on the main page. The user control contains
an image, and the image's source (src or ImageUrl) attribute still refers to a file path-the path of
an .ashx (IHttpHandler) file. The handler file puts the image's bytes into the response stream. A
byte array is used to send data to an Image field. Thus, the main question is: How does one
convert an image file—whether a JPEG, Bitmap, or other format—into an array of bytes? There
are several ways to accomplish this in .NET. One of the easiest ways is to use a concrete
implementation of the Streamclass. A stream in .NET is essentially an abstraction of a sequence
of bytes, whether these bytes came from a file, a TCP/IP socket, a database, or
wherever. Stream classes allow you to work with binary . A MemoryStream object is simply a
stream that uses memory as its backup store instead of some other medium. As a result,
a MemoryStream object usually provides better performance. Streams are flexible. You could,
for example, have used a FileStream object to open the image file directly and read it in. There
are certainly numerous other ways, too. The implementation here, however, is simple and

The basic solution emulates the most published assemblage of elements (published by me and
others), but I have added some twists for a better overall result and more control over the image.

Here are the steps:

1. Create a Web page

2. Define a SqlDataSource pointing to the Northwind's Categories table

3. Add a template column form the Smart tags menu and add a template column for the Picture

4. Add a UserControl to the project and drag and drop the UserControl into the Picture's template

5. On the UserControl add an <img> tag to the UserControl

6. Add a Generic Handler (.ashx file) to the project

7. Change the <img> tag's src property to refer to the Handler.ashx file

8. Add query parameters for the CategoryID, CategoryName, and Picture to the src's attribute

9. Add script blocks to the UserControl reference in the Web page. You want to daisy chain the
CategoryID, CategoryName, and Picture from the grid, to the UserControl, and pass it on to the
Handler.ashx file


<%@       Page   Language="VB"        AutoEventWireup="false"      CodeFile="Default.aspx.vb"
Inherits="_Default" %>

<%@ Register src="PhotoControl.ascx" tagname="PhotoControl" tagprefix="uc1" %>

 <!DOCTYPE       html   PUBLIC     "-//W3C//DTD       XHTML            1.0    Transitional//EN"

<html xmlns="">

<head runat="server">




  <form id="form1" runat="server">


     <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

    DataKeyNames="CategoryID" DataSourceID="SqlDataSource1">


      <asp:BoundField DataField="CategoryID" HeaderText="CategoryID"

       InsertVisible="False" ReadOnly="True" SortExpression="CategoryID" />

      <asp:BoundField DataField="CategoryName" HeaderText="CategoryName"

       SortExpression="CategoryName" />

      <asp:BoundField DataField="Description" HeaderText="Description"

       SortExpression="Description" />
     <asp:TemplateField HeaderText="Picture" SortExpression="Picture">


        <uc1:PhotoControl  ID="PhotoControl1"  runat="server"  CategoryID='<%#
Eval("CategoryID") %>' CategoryName='<%# Eval("CategoryName") %>' Picture='<%#
Eval("Picture") %>' />





   <asp:SqlDataSource ID="SqlDataSource1" runat="server"

    ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"

    SelectCommand="SELECT * FROM [Categories]"></asp:SqlDataSource>





The below code describes the user control. The Picture is placed in the Application cache and
everything else is passed as query parameters to THE ABOVE CODE FILE.

Partial Class PhotoControl

 Inherits System.Web.UI.UserControl

 Protected Sub Page_Unload() Handles Me.Unload

  Application(_) = _picture

 End Sub

 Private _categoryID As Integer

 Public Property CategoryID() As Integer


   Return _categoryID

  End Get


   _categoryID = Value

  End Set

 End Property

 Private _categoryName As String

 Public Property CategoryName() As String


   Return _categoryName

  End Get


   _categoryName = Value

  End Set

 End Property

 Private _picture As Byte()

 Public Property Picture() As Byte()


   Return _picture

  End Get


   _picture = Value

  End Set

 End Property

 Protected Sub Page_Load() Handles Me.Load

 End Sub

End Class

The below code describes how to handle the user control file:

  <%@ WebHandler Language="VB" Class="Handler" %>

   Imports System

  Imports System.Web

  Imports System.IO

  Imports System.Drawing

  Imports System.Drawing.Imaging

Public Class Handler : Implements IHttpHandler

     Public Sub ProcessRequest() Implements IHttpHandler.ProcessRequest

      Dim categoryID As String = context.Request.QueryString()

    Dim categoryName As String = context.Request.QueryString()

    Dim picture As Byte() = context.Application()

      If () Then Return

    Dim oleHeader As Integer ;

    Dim stream As MemoryStream = New MemoryStream()

    Dim image As Image = image.FromStream( )

    Dim bitmap As Bitmap = New Bitmap( )

    Dim graphics As Graphics = graphics.FromImage( )

     graphics.DrawImage( )

    Dim font As Font = New Font ()

    graphics.FillRectangle( )


    context.Response.ContentType = "image\jpeg"

    bitmap.Save( )

   End Sub

   Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable


     Return False

    End Get

   End Property

  End Class


From information that was found on the Web, it sounds like Northwind images were originally
created in Access-if memory serves this sounds right-and Access added an OLE (Object Linking
and Embedding) header. The first 78 bytes of the image represents the header not part of the
image. To display the Northwind images strip the header out of the image before rendering the

In the ProcessRequest method the MemoryStream strips the 78 leading bytes out of the image. If
you aren't using OLE images then create the MemoryStream without the second two parameters.

Customizing the images stored in database is easy and efficient when compared with other
things.Since we are using streams and converting the image into bytes it is easy even to store
data about the image even though if it is 3D or 2D image.

The rest of the code in ProcessRequest method converts the bytes to an image. The bytes are
retrieved from the Application cache. Next, a MemoryStream is created to load the bytes into a
stream and from there into an image. A Bitmap is created based on the size of the image and a
Graphics object (the GDI+ equivalent of an HDC canvas) is created from the bitmap. Once you
have the Graphics object you can perform any task supported by GDI+. In the example the
CategoryName is written on top of the Category picture.

When you are finished set the HttpContext response type and save the bitmap image to the

The results are show in Figure 1.

Figure 1: The images with text displayed in the grid

                                        4. ADVANTAGES

1. Storing of data in database is more secured and efficient.

2. Since we are using .NET framework it is much easier to code and help in doing operations on

images with respect to the database.

3. Disk space is cheap, so it is efficient of storing images in the database whenever possible.

4. Storing the images in the database makes them portable with the database.

5. The images get backed up when the database gets backed. As a result there is no chance of

losing the images and its properties.

6. When stored in databases it is less likely to be tampered.

7. Since databases follows ACID properties there is no chance of losing information of data.

8. Every immediate update of data can be updated when we use databases.

9. All types of images can be configured and operated using the databases.

10. Using databases it is easy to Display store and customize the 3D images.

11. Since we are dealing with databases and images streaming is the technique we will be using

for transfer of data in the network.

                                    5. CONCLUSION

Since we are using the databases we will not be encountered with issues such as memory space,
atomicity and many important functions. Here we can store all types of data. Northwind images
were created with Microsoft Access so they have a 78 byte OLE header. Strip the header out
before rendering the image. If you use the Web page-template column—UserControl—
IHttpHandler technique then you can send an image from the database right into a control, like a
grid column. In the IHttpHandler.ProcessRequest method you can use a Bitmap object to create a
Graphics object (GDI+ HDC/Canvas) and paint the image and anything else you want onto the
canvas and return that to the client. The result is images from the database with any
customization you can imagine. Since we are having many databases we can use any of them and
perform the operations.Now a days wide range of databases are available through which any type
of data and any kind of images can be stored. .NET can be used for storing and customizing the

                                      6. REFERENCES

1. Pro ASP.Net 4 in C# 2010 by Matthew MacDonald, Adam Freeman, Mario Szpuszta

2. ASP.NET 2.0 Cookbook, Second Edition.

3.O'Reillyreg; Oracle Books Chapters.

5. O'Reilly Oracle PL/SQL CD Bookshelf Mirror.





To top