I thought you where referring to images on the page. If you want images in a
new window you probably want to do a response.redirect in the onclick event
of the listbox. In that case you would not use the src= . That would only be
used for images on the page. If you're openning a new window then your image
is probably larger and higher quality. In that case, someone can just right
click it and save it to their disk. I don't think there is much you can do
about that. If you have a really high quality picture you can downgrade it
using an aspx file that calls up the image and then makes it a thumbnail or
smaller image using the info in my last post. You can also you a mask in
your code so that the user does not know the actual file name of the image
so they can't go back and try to get the base image. Hope this helps. There
was a site that had some other ideas, I will try to find it and post a link
when I get the chance.
Here is some code I use for some of my pictures. This codes does not mask
the file name but you could easily add it. Also if some of you file are tiff
then you would need to build that into the content type. I snipped this so
hopefully I got all the pieces.
sub Page_Load(sender as object, e as eventArgs)
dim strPic as string = request.querystring("_p")
dim strDesigner as string = request.querystring("_d") & ""
dim intWidth as int32 = ctype(request.querystring("_w"),int32)
dim intHeight as int32 = ctype(request.querystring("_h"),int32)
dim intQuality as int32 = ctype(request.querystring("_q"),int32)
dim myNewImage as system.drawing.image
dim intCacheTime as int32 = ctype(request.querystring("_c"),int32)
if intCacheTime > 3600 then intCacheTime = 3600
dim strFileLoc as string =
server.mappath(configurationSettings.AppSettings(" picroot"))
Response.ContentType = "image/jpeg"
if intCacheTime > 0 then
Response.Cache.SetExpires(DateTime.Now.AddSeconds( intCacheTime))
Response.Cache.SetCacheability(HttpCacheability.Pu blic)
Response.Cache.SetValidUntilExpires(True)
Response.Cache.VaryByParams("_p") = True
Response.Cache.VaryByParams("_h") = True
Response.Cache.VaryByParams("_c") = True
end if
try
select case intQuality
case is = 1
Dim bFlag as boolean = false
if intWidth = 0 then intWidth = 200
if intHeight = 0 then intHeight = 200
if strDesigner.length > 0 then bFlag = true
mynewimage = mgAdjustBitmap(strFileLoc & strPic, intWidth,
intHeight,bFlag,strDesigner)
case is = 2
if intWidth = 0 then intWidth = 90
if intHeight = 0 then intHeight = 90
mynewimage = mggetthumbnail(strFileLoc & strPic,intWidth,intHeight)
case is = 3
if intWidth = 0 then intWidth = 90
if intHeight = 0 then intHeight = 90
mynewimage = mggetthumbnail(strFileLoc & strPic,intWidth,intHeight)
dim strSaveLoc as string =
server.mappath(configurationSettings.AppSettings(" thumbroot"))
mynewimage.save(strSaveLoc & strpic,ImageFormat.Jpeg)
case is = 4
if intWidth = 0 then intWidth = 90
if intHeight = 0 then intHeight = 90
mynewimage = mggetthumbnail(strFileLoc & strPic,intWidth,intHeight)
dim strSaveLoc as string =
server.mappath(configurationSettings.AppSettings(" thumbroot"))
mynewimage.save(strSaveLoc & strpic,ImageFormat.Jpeg)
case else
if intWidth = 0 then intWidth = 90
if intHeight = 0 then intHeight = 90
mynewimage = mggetthumbnail(strFileLoc & strPic,intWidth,intHeight)
end select
mynewimage.Save(Response.OutputStream, ImageFormat.Jpeg)
mynewimage.dispose
catch
mynewimage= mggetthumbnail(strFileLoc & "npicture.jpg",240,180)
mynewimage.Save(Response.OutputStream, ImageFormat.Jpeg)
mynewimage.dispose
end try
End Sub
Function mgGetThumbNail(strFile as string, intWidth as integer, intHeight as
integer) as system.drawing.image
Dim myBitmap As bitmap = New Bitmap(strFile)
return mybitmap.getthumbnailimage(intWidth,intHeight,noth ing,nothing)
End Function
Function mgAdjustBitmap(strFile as string, intHorz as integer, intVert as
integer,bDrawTextFlag as boolean, strText as string) as bitmap
Dim mysize as size = new size(inthorz,intVert)
Dim myBitmap As bitmap = New Bitmap(strFile)
myBitmap = new bitmap(mybitmap,mysize)
if bDrawTextFlag then
myBitmap = mgDrawText(myBitmap, strText, 8,
color.blue,ctype(intHorz*.05,int32),ctype(intVert * .92,int32))
end if
return myBitmap
End Function
Function mgDrawText(objBitmap as bitmap, strText as string, intFontSize as
int32, sysColor as color, intHorzPos as int32, intVertPos as int32) as
bitmap
dim objGraphic as Graphics = Graphics.FromImage(objBitmap)
objGraphic.DrawString(strText,New Font("Tahoma",intFontSize),New
SolidBrush(sysColor),intHorzPos, intVertPos)
return objBitMap
End Function
"Vinay" <vi*************@nospam.yahoo.com> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
Thanks for the pointers Mike.
At the risk of sounding daft...what do you mean by?
You could have your src=yourpictureroutine.aspx and have your aspx file
do
Here's what I am trying to do:
I have an aspx page that has a list box, that has lets say 3 entries. When
the user clicks on each entry I want to show the corresponding image.
These images could be big tif files or jpg files. I want to show these images in
a new window. I've not worked a great deal with this before..hence the
confusion on my part.
Thanks!
Vinay
Response.ContentType = "image/jpeg"
mynewimage.Save(Response.OutputStream, ImageFormat.Jpeg)
Where mynewimage is a system.drawing.image from file. You could mask the
file name or put the pictures in a non-www directory and do something
like mynewimage=mgGetThumbNail(...)
Function mgGetThumbNail(strFile as string, intWidth as integer,
intHeight as integer) as system.drawing.image
Dim myBitmap As bitmap = New Bitmap(strFile)
return mybitmap.getthumbnailimage(intWidth,intHeight,noth ing,nothing)
End Function
Someone can still right click the picture and save the thumbnail. But they won't be able to get the actual image file. If you want to keep a higher
quality but smaller size you can use something like this.
Function mgAdjustBitmap(strFile as string, intHorz as integer, intVert
as integer) as bitmap
Dim mysize as size = new size(inthorz,intVert)
Dim myBitmap As bitmap = New Bitmap(strFile)
myBitmap = new bitmap(mybitmap,mysize)
return myBitmap 'myImg
End Function
Finally, once you have the image you can add text to the graphic using
something like this (snip)
dim objGraphic as Graphics = Graphics.FromImage(objBitmap)
objGraphic.DrawString(strText,New Font("Tahoma",intFontSize),New
SolidBrush(sysColor),intHorzPos, intVertPos)
return objBitMap
Hope this helps.
I have heard that some people put clear transparent images over the page
images so someone can't right click it but that seems to be a bit
extreme.
Hope this helps in some way.
"Vinay" <vi*************@nospam.yahoo.com> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl... Hi All:
I have a small application that stores images either in the database
or as files (depending on the user preference). I'm in the process of providing a web interface to this application.
1. If the images are stored in the DB then, every an image is
requested, it will need to be pulled out and a temp file created and then displayed?
What is the best way to do this?
2. If the images are stored as files, how do I ensure security? For
example if I store all the images in a folder called \database\images and that
has a file 3.tif or 3.jpg, how do I ensure that people dont point their
browsers to http://mysite/database/images/3.jpg ?
Any pointers would be very helpful :)
TIA
Vinay
vi******@nospam.yahoo.com.nospam