I have a gridview that gets its images from a database, the pictures are an unknown size. I need the pictures to display using the size they are saved into the database with unless they are wider than 1000px. If they are larger than 1000px wide I need to set thier size to 1000px. I canot set the size element on the image control to 1000px because smaller images are stretched and pixelated.
The following code is on the aspx page of the page which displays the images:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="620px">
asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" Width="620px"> <Columns>
<Columns> <asp:ImageField DataImageUrlField="Picnum" DataImageUrlFormatString="getpic.aspx?ID={0}">
<asp:ImageField DataImageUrlField="Picnum" DataImageUrlFormatString="getpic.aspx?ID={0}"> </asp:ImageField>
</asp:ImageField> </Columns>
</Columns></asp:GridView>
</asp:GridView>On the aspx.vb page getpic I have the following code to pull the image from the database and return it to the calling page:
Dim sqlString As String
sqlString As StringsqlString = "SQL that gets the pic"
"SQL that gets the pic"Dim sqconn As New SqlConnection(GetConnString())Dim sqlCmd As New SqlCommand(sqlString, sqconn)sqconn.Open()
Dim dr As SqlDataReaderdr = sqlCmd.ExecuteReader
dr.Read()
Response.BinaryWrite(dr("Pic"))Response.End()
If sqconn.State <> Data.ConnectionState.Closed Then
Dim sqconn As New SqlConnection(GetConnString())Dim sqlCmd As New SqlCommand(sqlString, sqconn)sqconn.Open()
Dim dr As SqlDataReaderdr = sqlCmd.ExecuteReader
dr.Read()
Response.BinaryWrite(dr("Pic"))Response.End()
If sqconn.State <> Data.ConnectionState.Closed Then
Dim sqlCmd As New SqlCommand(sqlString, sqconn)sqconn.Open()
Dim dr As SqlDataReaderdr = sqlCmd.ExecuteReader
dr.Read()
Response.BinaryWrite(dr("Pic"))Response.End()
If sqconn.State <> Data.ConnectionState.Closed Then
Dim dr As SqlDataReaderdr = sqlCmd.ExecuteReader
dr.Read()
Response.BinaryWrite(dr("Pic"))Response.End()
If sqconn.State <> Data.ConnectionState.Closed Then
"Pic"))Response.End()
If sqconn.State <> Data.ConnectionState.Closed Then
If sqconn.State <> Data.ConnectionState.Closed Thensqconn.Close()
End If
End If This code all works pulls the pictures and displays them in thier original sizes.