473,657 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Response.Output Stream

Hi all,

I'm using a second page to write dynamical generated images
into the outputstream. This avoids using tmp-files on disc.

My code-behind in the start aspx file is:

'Use second file to write into outputstream
Application("gr afix-obj") = ob
button.ImageUrl = "Grafix.asp x"
Panel.Controls. Add(button)

ob is the bitmap with the image! The file Grafix.aspx
contains only code behind:

Public Class grafix
Inherits System.Web.UI.P age

#Region " Web Form Designer Generated Code "

......

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles MyBase.Load

Dim ob As Bitmap = New Bitmap(830, 30)
ob = CType(Applicati on("grafix-obj"), Bitmap)
ob.Save(Respons e.OutputStream, Imaging.ImageFo rmat.Jpeg)
End Sub

End Class

I normally expect this to be working! But there is only the
'no image' sign on the imagebutton if I try.
I used the following code before, which worked well:

'Store as tmp file on disk
Dim tempfilepath As String = System.IO.Path. GetTempPath
ob.Save(tempfil epath &"temp.jpg",Ima ging.ImageForma t.Jpeg
button.ImageUrl = tempfilepath & "temp.jpg"

What is going wrong?

Thanks for each help
Jenny
Nov 17 '05 #1
3 5075
IN the Image.Save method, save it to a MemoryStream and after write the
memorystream to the response.output stream of the page.

Dim memstr as new memorystream()
Image.Save(mems tr,imageformat. jpeg)
memstr.writeto( response.output stream)
"Jenny" <j.********@SPA Mx-mail.ent> escribió en el mensaje
news:04******** *************** *****@phx.gbl.. .
Hi all,

I'm using a second page to write dynamical generated images
into the outputstream. This avoids using tmp-files on disc.

My code-behind in the start aspx file is:

'Use second file to write into outputstream
Application("gr afix-obj") = ob
button.ImageUrl = "Grafix.asp x"
Panel.Controls. Add(button)

ob is the bitmap with the image! The file Grafix.aspx
contains only code behind:

Public Class grafix
Inherits System.Web.UI.P age

#Region " Web Form Designer Generated Code "

.....

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles MyBase.Load

Dim ob As Bitmap = New Bitmap(830, 30)
ob = CType(Applicati on("grafix-obj"), Bitmap)
ob.Save(Respons e.OutputStream, Imaging.ImageFo rmat.Jpeg)
End Sub

End Class

I normally expect this to be working! But there is only the
'no image' sign on the imagebutton if I try.
I used the following code before, which worked well:

'Store as tmp file on disk
Dim tempfilepath As String = System.IO.Path. GetTempPath
ob.Save(tempfil epath &"temp.jpg",Ima ging.ImageForma t.Jpeg
button.ImageUrl = tempfilepath & "temp.jpg"

What is going wrong?

Thanks for each help
Jenny

Nov 17 '05 #2
| Private Sub Page_Load(ByVal sender As System.Object, ByVal
| e As System.EventArg s) Handles MyBase.Load
|
| Dim ob As Bitmap = New Bitmap(830, 30)
| ob = CType(Applicati on("grafix-obj"), Bitmap)
| ob.Save(Respons e.OutputStream, Imaging.ImageFo rmat.Jpeg)
| End Sub
|
| End Class
|
| I normally expect this to be working! But there is only the
| 'no image' sign on the imagebutton if I try.

Similar code works well for me, just specify content-type:
Response.Conten tType = "image/jpeg".

The following is code I use at http://webcam.rider.cz:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim BMP As Bitmap, GPH As Graphics
Dim RQ As System.Net.Http WebRequest
Dim RP As System.Net.Http WebResponse

Response.Conten tType = "image/jpeg"
Try
RQ = System.Net.WebR equest.Create(" http://epona:8000/" &
Request.UserHos tAddress)
RQ.UserAgent = Request.UserAge nt
RP = RQ.GetResponse( )
BMP = New Bitmap(RP.GetRe sponseStream())
GPH = System.Drawing. Graphics.FromIm age(BMP)
Catch EX As Exception
BMP = BMP.FromFile(Se rver.MapPath("/_gfx/wc-error.bmp"))
GPH = System.Drawing. Graphics.FromIm age(BMP)
GPH.DrawString( "The following exception occured:" & vbCrLf &
EX.Message, New Font("Courier New", 10, FontStyle.Bold, GraphicsUnit.Po int),
New SolidBrush(Colo r.White), 5, 400)
End Try
GPH.DrawImage(N ew Bitmap(Server.M apPath("/_gfx/wc-footer.bmp")), New
RectangleF(0, 460, 640, 20), New RectangleF(0, 0, 640, 20),
GraphicsUnit.Pi xel)
GPH.DrawString( "www.rider. cz | Prague CZ-EU | " &
Now.ToUniversal Time.ToString(" yyyy-MM-dd HH:mm:ss") & " GMT", New
Font("Courier New", 10, FontStyle.Bold, GraphicsUnit.Po int), New
SolidBrush(Colo r.White), 5, 462)
BMP.Save(Respon se.OutputStream ,
System.Drawing. Imaging.ImageFo rmat.Jpeg)
End Sub

--
Michal A. Valasek, Altair Communications, http://www.altaircom.net
Please do not reply to this e-mail, for contact see http://www.rider.cz
Nov 17 '05 #3
Here is how I did it. I didn't bother with code behind on this one because
there isn't anything other than code. I call the image by setting it's
ImageURL or NavigateURLprop erty to
pic.aspx?_p=abc .jpg&_w=123&_h= 123&_q=1 (for image, or 2 for thumb)

<%@ Page Language="VB" SmartNavigation ="false" Strict="true" %>
<%@ import Namespace="Syst em.Drawing" %>
<%@ import Namespace="Syst em.Drawing.Imag ing" %>
<%@ import Namespace="Syst em.Drawing.Draw ing2D" %>
<html>

<script language="vb" runat="server">
sub Page_Load(sende r as object, e as eventArgs)

dim strPic as string = request.queryst ring("_p")
dim intWidth as int32 = ctype(request.q uerystring("_w" ),int32)
dim intHeight as int32 = ctype(request.q uerystring("_h" ),int32)
dim intQuality as int32 = ctype(request.q uerystring("_q" ),int32)
dim myNewImage as system.drawing. image
dim strFileLoc as string =
server.mappath( configurationSe ttings.AppSetti ngs("picroot"))
try
select case intQuality
case is = 1
if intWidth = 0 then intWidth = 200
if intHeight = 0 then intHeight = 200

mynewimage = mgAdjustBitmap( strFileLoc & strPic, intWidth, intHeight)
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.Outpu tStream, ImageFormat.Jpe g)
catch
mynewimage= mggetthumbnail( strFileLoc & "npicture.jpg", 90,90)
mynewimage.Save (Response.Outpu tStream, ImageFormat.Jpe g)
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.getthu mbnailimage(int Width,intHeight ,nothing,nothin g)
mybitmap.dispos e
End Function

Function mgAdjustBitmap( strFile as string, intHorz as integer, intVert as
integer) as bitmap

Dim mysize as size = new size(inthorz,in tVert)
Dim myBitmap As bitmap = New Bitmap(strFile)
dim myImg as bitmap = new bitmap(mybitmap , mysize)
mybitmap.dispos e
return myImg
End Function
</script>

</html>
"Jenny" <j.********@SPA Mx-mail.ent> wrote in message
news:04******** *************** *****@phx.gbl.. .
Hi all,

I'm using a second page to write dynamical generated images
into the outputstream. This avoids using tmp-files on disc.

My code-behind in the start aspx file is:

'Use second file to write into outputstream
Application("gr afix-obj") = ob
button.ImageUrl = "Grafix.asp x"
Panel.Controls. Add(button)

ob is the bitmap with the image! The file Grafix.aspx
contains only code behind:

Public Class grafix
Inherits System.Web.UI.P age

#Region " Web Form Designer Generated Code "

.....

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles MyBase.Load

Dim ob As Bitmap = New Bitmap(830, 30)
ob = CType(Applicati on("grafix-obj"), Bitmap)
ob.Save(Respons e.OutputStream, Imaging.ImageFo rmat.Jpeg)
End Sub

End Class

I normally expect this to be working! But there is only the
'no image' sign on the imagebutton if I try.
I used the following code before, which worked well:

'Store as tmp file on disk
Dim tempfilepath As String = System.IO.Path. GetTempPath
ob.Save(tempfil epath &"temp.jpg",Ima ging.ImageForma t.Jpeg
button.ImageUrl = tempfilepath & "temp.jpg"

What is going wrong?

Thanks for each help
Jenny

Nov 17 '05 #4

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

Similar topics

1
2931
by: Neil Woodvine | last post by:
***Scenario ... I have a DataList with a hyperlink WebControl in the Item Template. I want to display a 64x64 image in the Hyperlink and set the NavigateURL to the full size image. ***Source Data Item for Databinding is a class with 2 props ... URL Description ***MyMainPage.aspx Page_Load Code ...
3
13770
by: Zoury | last post by:
Hi folks ! :O) I'm trying to show a PDF in ASP.NET but I can't get to work properly. here's a portion of my code : '** Dim ms As MemoryStream = DirectCast(m_report.FormatEngine.ExportToStream(reqContext), MemoryStream) If (fileName Is Nothing) Then
6
9805
by: Joseph | last post by:
Hi! I have this webpage that contains some panels and buttons. I also want to output an Image to that same page, but when I save the image to the OutputStream using the Image.Save (Response.OutputStream) method, the panels and buttons get overwritten and only the image appears. Is there a way to preserve the buttons and output the image at the same time? How do I append to the Response.OutputStream? Many thanks!
1
2185
by: Joseff | last post by:
I have this Bitmap object declared and outputted to the browswer this way: invoiceBMP.Save(Response.OutputStream, ImageFormat.Gif); However, the result is that the existing static controls of the page gets overwritten and only the image appears. How do i output the bitmap image to the browser without using Response.OutputStream so as not to overwrite the whole web page?
2
1875
by: 1 | last post by:
Hi there, A while back I wrote some code using the .Net drawing libraries... this code takes a datatable and generates a pie or bar chart on the fly. The resulting image is returned using response.outputstream. While this is a budget solution it suited the purpose at the time. I now want to reuse this code but because using response.outputstream only allows the resulting image file to be displayed (by itself with no page around it) I...
0
1088
by: Jared | last post by:
Please note that I posted in the framework.drawing group as well. Hello all, I want to display multipart tiff images in a web browser using the response.outputstream. I know how to do it with any other image type, but, when I run into the tiff I get a generic gdi+ error. How do you send the entire tiff image to the response.outputstream??? TIA,
0
1346
by: Dave | last post by:
Hi, I'm trying to download a pdf from a secure location and writ e the response to the browser as listed below. However, the form that runs this codes appears to postback when I encounter the Response.OutputStream??? WebClient client = new WebClient(); client.Credentials = new NetworkCredential("username", "password"); byte pdfBytes = client.DownloadData(strUrl); Response.ContentType = "application/pdf";...
0
1422
by: Chris Ashley | last post by:
I'm writing files directly to Response.OutputStream... setting the headers like so: HttpContext.Current.Response.Buffer = false; HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = "binary/octet- stream"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + strOutputFilename); long lngSize = GetFileSize(strFTPURL, strFileName);
3
2893
by: kellygreer1 | last post by:
PHP will alllow you to build up an entire page and before sending that out as the response.... you can grab all the text and do search and replaces, add comments, make more CSS/XHTML compliant, etc... I have bee trying to do the same thing in ASP.NET by manipulating the Response.OutputStream. I keep getting the error: Exception Details: System.ArgumentException: Stream was not readable. On this line: StreamReader sr = new...
0
8413
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7352
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.