473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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.CloseConnectio n)
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.
************************************************** ********************
Nov 19 '05 #1
3 1279
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
Nov 19 '05 #2
Cor Ligthert wrote:
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.
************************************************** ********************
Nov 19 '05 #3

"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
Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Constantine Kakoushis | last post by:
Hi, I was previously running from my home test server (Suse 9.0) but have recently uploaded to my ISP. Since then (I think) images that have been resized on the server (resulting in .pjpeg...
3
by: Steve Castellotti | last post by:
Hey all-- I have a simple photo website written in python. I would like to be able to use Python Imaging Library (or similar) to read an image file from the disk, resize/thumbnail it in memory,...
1
by: John Scott | last post by:
I am storing an image in an SQL database and have one field as an image datatype. I am also using a webservice to transport data. I want to be able to resize the image and pass back a thumbnail...
1
by: toma | last post by:
Hi! I found out how to manipulate (read,resize, etc..) images using System.Drawin namespace from this site: http://authors.aspalliance.com/chrisg/default.asp?category=9 But i don't know how to...
6
by: Neo Geshel | last post by:
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...
9
by: Maxi | last post by:
There is a very good javascript available at the following link that displays image and text wherever mouse follows a link. http://www.dynamicdrive.com/dynamicindex4/imagetooltip.htm I have a...
1
by: Voodoo Jai | last post by:
I have a dbn of images that I retrieve using SQL statements in dreamweaver. I want to get the file name using SQL and then place it into the "getimagesize" function and then use this info...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
1
oranoos3000
by: oranoos3000 | last post by:
hi would you please help me i have a online shopping center that i show pictures of the my product in home page. in the InterExplorer pictures is shown correctly but in Firefox browser is shown...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.