Did I do this correctly? - Display resized image from DB.

N

Neo Geshel

Greetings.

I am making an admin interface, which allows me to upload photos to an
access DB. The admin interface also needs to display the uploaded
photos, but only needs to show them at a maximum resolution of 100px per
side. All photos will be JPEG. Below is a showimage.aspx file that
allows me to display the images from the database in the admin
interface. It doesn't seem to work right, so I believe I did something
wrong. It is supposed to take two variables (the table name and the
desired key) and extract the image, resize it proportionally, and then
display it. Could someone please look over it and correct any mistakes?

<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script runat=server>
Public Sub Page_Load(sender As Object, e As EventArgs)
Dim strTable as String = Request.QueryString("table")
Dim strID as String = Request.QueryString("id")
Dim myConn as New
OleDbConnection(ConfigurationSettings.AppSettings("strConn"))
Dim myCmd as New OleDbCommand("SELECT [Image] FROM " & strTable & "
WHERE [ID] = " & strID, myConn)
Try
myConn.Open()
Dim myDataReader as OleDbDataReader
myDataReader = myCmd.ExecuteReader(CommandBehavior.CloseConnection)
Do While (myDataReader.Read())
Dim imgStream As Stream = myDataReader.Item("Image")
Dim imgbin() As Byte
imgbin = createThumbnail(imgStream, 100, 100)
Response.ContentType="image/jpeg"
Response.BinaryWrite(imgbin)
Loop
myConnection.Close()
End Try
End Sub
Private Function createThumbnail(ByVal ImageStream As Stream, ByVal
tWidth As Double, ByVal tHeight As Double) As Byte()
Dim g As System.Drawing.Image
=System.Drawing.Image.FromStream(ImageStream)
Dim thumbSize As New Size()
thumbSize =NewthumbSize(g.Width, g.Height, tWidth, tHeight)
Dim imgOutput As New Bitmap(g, thumbSize.Width, thumbSize.Height)
Dim imgStream As New MemoryStream()
Dim thisFormat = g.RawFormat
imgOutput.Save(imgStream, thisFormat)
Dim imgbin(imgStream.Length) As Byte
imgStream.Position = 0
Dim n As Int32 = imgStream.Read(imgbin, 0, imgbin.Length)
g.Dispose()
imgOutput.Dispose()
Return imgbin
End Function
Function NewthumbSize(ByVal currentwidth As Double, ByVal currentheight
As Double, ByVal newWidth As Double, ByVal newHeight As Double)
Dim tempMultiplier As Double
If currentheight > currentwidth Then ' portrait
tempMultiplier = newHeight / currentheight
Else
tempMultiplier = newWidth / currentwidth
End If
Dim NewSize As New Size(CInt(currentwidth * tempMultiplier),
CInt(currentheight * tempMultiplier))
Return NewSize
End Function
</script>


Thanks.
....Geshel
--
**********************************************************************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
**********************************************************************
 
C

Cor Ligthert

Neo,

This is typical a question for the newsgroup

microsoft.public.dotnet.languages.vb

(If you search that newsgroup using the Google newsgroups search you
probably find your answer as well, however you can ask of course too)

I hope this helps,

Cor
 
N

Neo Geshel

Cor said:
Neo,

This is typical a question for the newsgroup

microsoft.public.dotnet.languages.vb

(If you search that newsgroup using the Google newsgroups search you
probably find your answer as well, however you can ask of course too)

I hope this helps,

Cor

Why are these two newsgroups not appropriate? The code in question is
the showimage.aspx page, which is meant to be referenced by an
<asp:image /> tag inside of another asp.net page. As such, it is an
appropriate question for microsoft.public.dotnet.framework.aspnet. As
well, the code in question contains a DB connection using ADO.NET, so it
is also an appropriate question for
microsoft.public.dotnet.framework.adonet, since I may have done
something wrong with the DB access itself.

I was under the impression that microsoft.public.dotnet.languages.vb
only goes into general VB.NET programming for Windows, and not VB for
ASP.NET.

....Geshel
--
**********************************************************************
My reply-to is an automatically monitored spam honeypot. Do not use it
unless you want to be blacklisted by SpamCop. Please reply to my first
name at my last name dot org.
**********************************************************************
 
C

Cor Ligthert

"Neo Geshel"
Why are these two newsgroups not appropriate?

Did I say that?
I was under the impression that microsoft.public.dotnet.languages.vb only
goes into general VB.NET programming for Windows, and not VB for ASP.NET.
Why? Your code is complete VBNet language.

In addition, because of the fact that you create your image on the
serverside complete in memory is the change in that newsgroup to get
solution higher. (Better it is often asked and answered there by more
persons, although the most by Bob Powell).

You are not only compressing using the standard thumbnail however as well
using the drawing classes.

My answer was only to help you.

However feel free not to take my advise.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top