`
justdoithz
  • 浏览: 48919 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论

HttpResponse..::.OutputStream 属性

阅读更多

启用到输出 HTTP 内容主体的二进制输出。

示例

<!---->

下面的示例调用 Save 方法将一个 Bitmap 对象保存到 OutputStream 属性中,并将图像转换为 JPEG 格式。然后,代码调用 Bitmap 对象和 Graphics 对象的 Dispose 方法,释放它们正在使用的资源。最后,代码调用 Flush 方法将响应的内容发送到请求客户端。

有关完整示例,请参见 HttpResponse 类。

Visual Basic
<%@ 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)
      ' Set the page's content type to JPEG files
      ' and clear all response headers.
      Response.ContentType = "image/jpeg"
      Response.Clear()

      ' Buffer response so that page is sent
      ' after processing is complete.
      Response.BufferOutput = True

      ' 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)

      ' 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()
   End Sub 'Page_Load

</script>
<html  >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>

<%@ 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)
    {
        // Set the page's content type to JPEG files
        // and clear all response headers.
        Response.ContentType = "image/jpeg";
        Response.Clear();

        // Buffer response so that page is sent
        // after processing is complete.
        Response.BufferOutput = true;

        // 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);

        // 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();
    }

</script>
<html  >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>
分享到:
评论

相关推荐

    stackerjs-http

    httpResponse . setContent ( { status : true } ) ; httpResponse . setContent ( "Everything is ok" ) ; // or httpResponse . setContent ( new Buffer ( "Something" ) ) ; // or httpResponse . setStatusCode...

    python 零基础学习篇python课程django框架django请求和响应16 HttpResponse .mp4

    python 零基础学习篇

    HttpResponse的Output与OutputStream、Filter关系与区别介绍

    在网上经常看见有这样的代码HttpResponse response = HttpContext.Current.Response;现在我也来说说这几个东东是什么吧

    Android如何从服务器获取图片

    HttpResponse response = client.execute(get); HttpEntity entity = response.getEntity(); InputStream is = entity.getContent(); pic = BitmapFactory.decodeStream(is); } catch (ClientProtocolException...

    Android 创建HttpPost对象 获取HTTP连接.rar

      if(httpResponse.getStatusLine().getStatusCode()==200){//连接成功   String result = EntityUtils.toString(httpResponse.getEntity());//获得资源   result = result.replaceAll("\r\n|\n\r|\r|\n", "");...

    Android应用开发实验指导书.doc

    配置JDK: XP:右键"我的电脑"("属性"("高级"("环境变量" WIN7:右键"我的电脑"("高级系统设置"("环境变量" 新建系统变量: JAVA_HOME,C:\Program Files (x86)\Java\jdk1.6.0_18(JDK安装目录)。 PATH,%JAVA_...

    org.apache.http源代码和jar包

    import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache....

    import org.apache.http

    import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache....

    org.apache.HTTP需要的jar包.zip

    org.apache.HTTP需要的jar包,常用于Web开发,比如JSP+Servlet的学习,SSM\SSH等

    Django实现跨域的2种方法

    return HttpResponse('%s("我要上鸭王")' %(callback,)); # javascript function submitJsonp4() { $.ajax({ url: 'http://127.0.0.1:9000/xiaokai.html', type: 'GET', //写post 没有用 只能发get dataType: ...

    Python实现简单http服务器

    1.浏览器中输入网站地址:172.20.52.163:20014 ...代码实现 server.py #!/usr/bin/python ...def HttpResponse(header,whtml): f = file&#40;whtml&#41; contxtlist = f.readlines() context = ''

    python实现简单http服务器功能

    背景 ...1.浏览器中输入网站地址:172.20.52.163:20014 ...代码实现 server.py #!/usr/bin/python ...def HttpResponse(header,whtml): f = file&#40;whtml&#41; contxtlist = f.readlines() context = ''.

    org.apache.http 相关的jar包

    import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache....

    is-ok:检查 HTTP 响应是否成功

    接受的响应对象,具有statusCode属性,第一参数,并返回true ,如果状态码是内2xx范围,否则返回false 。 可选地,它将回调作为第二个参数,仅当响应不成功时才使用错误对象调用它。 错误设置了statusCode 、 ...

    chilkat-9.5.0-库+注册机

    HttpResponse Imap JavaKeyStore JsonArray JsonObject Jwe Jws Jwt KeyContainer Log MailMan Mailboxes MessageSet Mht Mime Ntlm OAuth1 OAuth2 Pem Pfx PrivateKey Prng PublicKey Rest Rsa Rss SFtp SFtpDir ...

    Cookie的使用

    在Cookie介绍中 我们了解到Cookie是基于Set Cookie响应头和Cookie请求头工作的 服务器通过response对象的addHeader 方法将cookie发送给浏览器 然后浏览器通过Cookie请求头将cookie再送回服务器

    node.js中的http.response.end方法使用说明

    方法说明: 结束响应,告诉客户端所有消息已经发送。当所有要返回的内容发送完毕时,该函数必须被调用一次。 如何不调用该函数,客户端将永远处于等待状态。 语法: 代码如下: response.end([data], [encoding]) ...

    新浪微博授权代码及测试结果.zip

    String strResult = EntityUtils.toString(httpResponse.getEntity()); Log.e("WeiboKu", "strResult :"+strResult); return strResult; } else { Log.e("WeiboKu", "strResult Error:"+statusCode); return...

    http依赖jar包.zip

    import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.ParseException; import org.apache.http.client.ClientProtocolException; import org.apache....

Global site tag (gtag.js) - Google Analytics