HttpResponse.OutputStream 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
나가는 HTTP 콘텐츠 본문에 대한 이진 출력을 활성화합니다.
public:
property System::IO::Stream ^ OutputStream { System::IO::Stream ^ get(); };
public System.IO.Stream OutputStream { get; }
member this.OutputStream : System.IO.Stream
Public ReadOnly Property OutputStream As Stream
속성 값
나가는 HTTP 콘텐츠 본문의 원시 콘텐츠를 나타내는 IO Stream입니다.
예외
OutputStream
를 사용할 수 없는 경우
예제
다음 예제에서는 메서드를 Save 호출하여 개체를 Bitmap 속성에 OutputStream 저장하고 이미지를 JPEG 형식으로 변환합니다. 그런 다음, 코드는 개체와 개체에서 Bitmap Dispose 메서드를 Graphics 호출하여 사용하던 리소스를 해제합니다. 마지막으로, 코드는 메서드를 Flush 호출하여 요청 클라이언트에 응답의 콘텐츠를 보냅니다.
전체 예제는 클래스를 참조하세요 HttpResponse .
<%@ Page Language="C#" %>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.Drawing.Imaging" %>
<%@ import Namespace="System.Drawing.Drawing2D" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
private void Page_Load(object sender, EventArgs e)
{
// <snippet2>
// Set the page's content type to JPEG files
// and clears all content output from the buffer stream.
Response.ContentType = "image/jpeg";
Response.Clear();
// Buffer response so that page is sent
// after processing is complete.
Response.BufferOutput = true;
// </snippet2>
// Create a font style.
Font rectangleFont = new Font(
"Arial", 10, FontStyle.Bold);
// Create integer variables.
int height = 100;
int width = 200;
// Create a random number generator and create
// variable values based on it.
Random r = new Random();
int x = r.Next(75);
int a = r.Next(155);
int x1 = r.Next(100);
// Create a bitmap and use it to create a
// Graphics object.
Bitmap bmp = new Bitmap(
width, height, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bmp);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.Clear(Color.LightGray);
// Use the Graphics object to draw three rectangles.
g.DrawRectangle(Pens.White, 1, 1, width-3, height-3);
g.DrawRectangle(Pens.Aquamarine, 2, 2, width-3, height-3);
g.DrawRectangle(Pens.Black, 0, 0, width, height);
// Use the Graphics object to write a string
// on the rectangles.
g.DrawString(
"ASP.NET Samples", rectangleFont,
SystemBrushes.WindowText, new PointF(10, 40));
// Apply color to two of the rectangles.
g.FillRectangle(
new SolidBrush(
Color.FromArgb(a, 255, 128, 255)),
x, 20, 100, 50);
g.FillRectangle(
new LinearGradientBrush(
new Point(x, 10),
new Point(x1 + 75, 50 + 30),
Color.FromArgb(128, 0, 0, 128),
Color.FromArgb(255, 255, 255, 240)),
x1, 50, 75, 30);
// <snippet3>
// Save the bitmap to the response stream and
// convert it to JPEG format.
bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
// Release memory used by the Graphics object
// and the bitmap.
g.Dispose();
bmp.Dispose();
// Send the output to the client.
Response.Flush();
// </snippet3>
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.Drawing.Imaging" %>
<%@ import Namespace="System.Drawing.Drawing2D" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Private Sub Page_Load(sender As Object, e As EventArgs)
' <snippet2>
' Set the page's content type to JPEG files
' and clears all content output from the buffer stream.
Response.ContentType = "image/jpeg"
Response.Clear()
' Buffer response so that page is sent
' after processing is complete.
Response.BufferOutput = True
' </snippet2>
' Create a font style.
Dim rectangleFont As New Font( _
"Arial", 10, FontStyle.Bold)
' Create integer variables.
Dim height As Integer = 100
Dim width As Integer = 200
' Create a random number generator and create
' variable values based on it.
Dim r As New Random()
Dim x As Integer = r.Next(75)
Dim a As Integer = r.Next(155)
Dim x1 As Integer = r.Next(100)
' Create a bitmap and use it to create a
' Graphics object.
Dim bmp As New Bitmap( _
width, height, PixelFormat.Format24bppRgb)
Dim g As Graphics = Graphics.FromImage(bmp)
g.SmoothingMode = SmoothingMode.AntiAlias
g.Clear(Color.LightGray)
' Use the Graphics object to draw three rectangles.
g.DrawRectangle(Pens.White, 1, 1, width - 3, height - 3)
g.DrawRectangle(Pens.Aquamarine, 2, 2, width - 3, height - 3)
g.DrawRectangle(Pens.Black, 0, 0, width, height)
' Use the Graphics object to write a string
' on the rectangles.
g.DrawString("ASP.NET Samples", rectangleFont, SystemBrushes.WindowText, New PointF(10, 40))
' Apply color to two of the rectangles.
g.FillRectangle( _
New SolidBrush( _
Color.FromArgb(a, 255, 128, 255)), _
x, 20, 100, 50)
g.FillRectangle( _
New LinearGradientBrush( _
New Point(x, 10), _
New Point(x1 + 75, 50 + 30), _
Color.FromArgb(128, 0, 0, 128), _
Color.FromArgb(255, 255, 255, 240)), _
x1, 50, 75, 30)
' <snippet3>
' Save the bitmap to the response stream and
' convert it to JPEG format.
bmp.Save(Response.OutputStream, ImageFormat.Jpeg)
' Release memory used by the Graphics object
' and the bitmap.
g.Dispose()
bmp.Dispose()
' Send the output to the client.
Response.Flush()
' </snippet3>
End Sub 'Page_Load
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
</form>
</body>
</html>
설명
.NET Framework 버전 2.0부터 속성에서 반환된 OutputStream IO 스트림의 메서드를 사용하는 Stream.Write(Byte[], Int32, Int32) 경우 다음 예외가 throw될 수 있습니다.
ArgumentOutOfRangeException- 매개 변수가
offset
음수이거나count
매개 변수 길이에서buffer
매개 변수를 뺀offset
값이 0보다 작거나 같은 경우ArgumentNullException매개 변수
null
가 .인buffer
경우 .