Get Image Size From SQL Server

Results 1 to 4 of 4

Thread: Get Image Size From SQL Server

  1. #1
    Join Date
    Dec 1969
    Posts
    8

    Default Get Image Size From SQL Server

    I&#039;m using the script below to display an image that resides in a SQL Server database. The script works fine but I would like to add one feature. Can someone help me with the code to get and display the image&#039;s width and height values.<BR><BR>&#060;script language="VB" runat="server"&#062;<BR>Sub Page_Load(sender As Object, e As EventArgs)<BR> Dim imgid As String = Request.QueryString("id")<BR> Dim strSQLQuery As String = "SELECT img_name, img_data, img_contenttype FROM image WHERE img_pk=" & imgid <BR> Dim objConnection As New OleDbConnection<BR> objConnection = New OleDbConnection("Provider=SQLOLEDB;Integrated Security=SSPI;Initial Catalog=ImageDemo;Data Source=Nashville;")<BR> Dim objCommand As OleDbCommand = New OleDbCommand(strSQLQuery, objConnection)<BR> objConnection.Open()<BR> Dim myDataReader As OleDbDataReader = objCommand.ExecuteReader()<BR> myDataReader.Read()<BR> Response.ContentType = (myDataReader.Item(("img_contenttype")).ToString() )<BR> Response.BinaryWrite(myDataReader.Item("img_data") )<BR> objConnection.Close()<BR>End Sub<BR>&#060;/script&#062;<BR>&#060;html&#062;<BR>&#060;body&#06 2;<BR>&#060;form runat="server"&#062;<BR>&#060;asp:textbox ID="text1" runat="server" /&#062;<BR>&#060;/form&#062;<BR>&#060;/body&#062;<BR>&#060;/html&#062;

  2. #2
    Join Date
    Dec 1969
    Posts
    3,921

    Default Here is an ASP example

    Sorry, don&#039;t have a .NET code example. You can just<BR>convert the syntax:<BR><BR>http://www.eggheadcafe.com/forums/forumsearchbranch.asp?THREADID=1522

  3. #3
    Join Date
    Dec 1969
    Posts
    8

    Default Would Still Like To See ASP.Net Code

    Thanks. Will take a look at it but would still like to see ASP.Net code.

  4. #4
    Join Date
    Dec 1969
    Posts
    8

    Default Problem Solved

    For those of you looking to address this same issue, here&#039;s the code to get an image&#039;s width and height values that resides in a SQL Server database (comment out Response.ContentType and Response.BinaryWrite lines from code in first post and insert the following):<BR><BR>Dim Data As Byte() = myDataReader.Item("img_data")<BR>Dim ms As MemoryStream = New MemoryStream(Data)<BR>Dim i = System.Drawing.Image.FromStream(ms)<BR>Dim imgHeight<BR>Dim imgWidth<BR>imgHeight = i.Height<BR>imgWidth = i.Width


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


More ASP Resources

Resources:
-- ASP Articles
-- ASP.NET Information
-- 4Guys ASP F.A.Q.
-- ASPFAQs.com
-- ASP Coding Tips
-- Related Web Technologies
-- User Tips!!
-- JavaScripts


Development Centers
-- HTML5 Development Center
-- Windows Mobile Development Center
-- Android Development Center
-- Cloud Development Project Center


Development Technology
Check out these sites for more articles, tutorials, FAQs, discussions, and code!
-- CodeGuru.com
-- VBForums.com
-- DevX.com
-- Developer.com
-- HTMLGoodies