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.Public)
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,nothing,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