|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Did I do this correctly? - Display resized image from DB.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. ********************************************************************** 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 Cor Ligthert wrote:
Show quoteHide quote > Neo, Why are these two newsgroups not appropriate? The code in question is > > 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 > > 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. ********************************************************************** "Neo Geshel"
> Did I say that?> Why are these two newsgroups not appropriate? > Why? Your code is complete VBNet language.> 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. > 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
Other interesting topics
Session State stateserver or Sql Server
Asynchronous Call <Head>Tag PostBack problem HttpWebRequest.GetResponse on POST returns 405 method not allowed 2.0 App-Code Folder Support for 'Code-Behind' LDAP Query Help Width of Label Cannot use integrated security from a thread in ASP.Net/ Windows 2 adding html to body |
|||||||||||||||||||||||