Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > response.contenttype

Reply
Thread Tools

response.contenttype

 
 
Mike Kansky
Guest
Posts: n/a
 
      06-16-2006
I have an image.aspx that does the following:

if request("s")=1 then
response.redirect(http://www.domain.com/image1.gif)
else
response.redirect(http://www.domain.com/image2.gif)
end if

And then i use it like that in my pages: <img src="images.aspx?s=1">

Now the question:

I do not like the way i do it, i think it is better and faster to do it by
using response.contenttype="image/gif" in image.aspx. Am i right?

if i am right could anyone give me an example of code? I found some examples
but they were getting the image from database and saving into the response
object.
How do i do the same with an URL image?

Thanks a lot!


 
Reply With Quote
 
 
 
 
vMike
Guest
Posts: n/a
 
      06-17-2006

"Mike Kansky" <> wrote in message
news:%...
>I have an image.aspx that does the following:
>
> if request("s")=1 then
> response.redirect(http://www.domain.com/image1.gif)
> else
> response.redirect(http://www.domain.com/image2.gif)
> end if
>
> And then i use it like that in my pages: <img src="images.aspx?s=1">
>
> Now the question:
>
> I do not like the way i do it, i think it is better and faster to do it by
> using response.contenttype="image/gif" in image.aspx. Am i right?
>
> if i am right could anyone give me an example of code? I found some
> examples but they were getting the image from database and saving into the
> response object.
> How do i do the same with an URL image?
>
> Thanks a lot!


You can stream it from a file something along the lines of the following


if request("s")=1 then


Response.ClearContent
Response.ContentType = "image/jpeg"
......
snip
Dim myImg as system.drawing.image =
system.drawing.image.fromfile(Yourfilenameandpath)
you can resize here if needed
dim origSize as Size = myImg.Size
if origSize.width < origSize.height then 'must be portrait
dim intHolder as int32 = intHorz
intHorz = intVert
intVert = intHolder
end if
Dim mysize as size = new size(intHorz,intVert)
Dim myBitmap as new bitmap(myImg,mysize)
mybitmap.Save(Response.OutputStream, ImageFormat.Jpeg)
mybitmap.dispose()
myImg.dispose()


 
Reply With Quote
 
 
 
 
Mike Kansky
Guest
Posts: n/a
 
      06-17-2006
Can i do something like that from URL where image is located?




"vMike" <> wrote in message
news:MAJkg.12642$.. .
>
> "Mike Kansky" <> wrote in message
> news:%...
>>I have an image.aspx that does the following:
>>
>> if request("s")=1 then
>> response.redirect(http://www.domain.com/image1.gif)
>> else
>> response.redirect(http://www.domain.com/image2.gif)
>> end if
>>
>> And then i use it like that in my pages: <img src="images.aspx?s=1">
>>
>> Now the question:
>>
>> I do not like the way i do it, i think it is better and faster to do it
>> by using response.contenttype="image/gif" in image.aspx. Am i right?
>>
>> if i am right could anyone give me an example of code? I found some
>> examples but they were getting the image from database and saving into
>> the response object.
>> How do i do the same with an URL image?
>>
>> Thanks a lot!

>
> You can stream it from a file something along the lines of the following
>
>
> if request("s")=1 then
>
>
> Response.ClearContent
> Response.ContentType = "image/jpeg"
> .....
> snip
> Dim myImg as system.drawing.image =
> system.drawing.image.fromfile(Yourfilenameandpath)
> you can resize here if needed
> dim origSize as Size = myImg.Size
> if origSize.width < origSize.height then 'must be portrait
> dim intHolder as int32 = intHorz
> intHorz = intVert
> intVert = intHolder
> end if
> Dim mysize as size = new size(intHorz,intVert)
> Dim myBitmap as new bitmap(myImg,mysize)
> mybitmap.Save(Response.OutputStream, ImageFormat.Jpeg)
> mybitmap.dispose()
> myImg.dispose()
>



 
Reply With Quote
 
vMike
Guest
Posts: n/a
 
      06-17-2006

"Mike Kansky" <> wrote in message
news:...
> Can i do something like that from URL where image is located?
>

Sure. In its simplest form you would do this.

<%@ Page Language="VB" %>
<%@ Import namespace="System.Net" %>
<%@ Import namespace="System.IO" %>
<%@ Import namespace="System.Drawing" %>
<%@ Import namespace="System.Drawing.Imaging" %>

<script runat=server language=vb>

Sub Page_Load(sender as object, e as eventargs)
GetPictureStream("http://yoururihere")

End Sub


Sub GetPictureStream(strURI as string)
Response.ClearContent
Response.ContentType = "image/jpeg"
Dim client As New WebClient()
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.2; .NET CLR 1.0.3705")
Dim data As Stream = client.OpenRead(strURI)
dim myimg as system.drawing.image =
system.drawing.image.fromstream(data)
myimg.Save(Response.OutputStream, ImageFormat.Jpeg)
myimg.dispose()
data.Close()

End Sub
</script>




 
Reply With Quote
 
Mike Kansky
Guest
Posts: n/a
 
      06-18-2006
Thanks Mike!

Last question:

Is it really faster then me doing response.redirect in Image.aspx?
Are there any other advantages of using contenttype?
"vMike" <> wrote in message
news:bCQkg.9202$y%...
>
> "Mike Kansky" <> wrote in message
> news:...
>> Can i do something like that from URL where image is located?
>>

> Sure. In its simplest form you would do this.
>
> <%@ Page Language="VB" %>
> <%@ Import namespace="System.Net" %>
> <%@ Import namespace="System.IO" %>
> <%@ Import namespace="System.Drawing" %>
> <%@ Import namespace="System.Drawing.Imaging" %>
>
> <script runat=server language=vb>
>
> Sub Page_Load(sender as object, e as eventargs)
> GetPictureStream("http://yoururihere")
>
> End Sub
>
>
> Sub GetPictureStream(strURI as string)
> Response.ClearContent
> Response.ContentType = "image/jpeg"
> Dim client As New WebClient()
> client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE
> 6.0; Windows NT 5.2; .NET CLR 1.0.3705")
> Dim data As Stream = client.OpenRead(strURI)
> dim myimg as system.drawing.image =
> system.drawing.image.fromstream(data)
> myimg.Save(Response.OutputStream, ImageFormat.Jpeg)
> myimg.dispose()
> data.Close()
>
> End Sub
> </script>
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57