• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >ASP.NET > ASP.NET中图片显示方法实例

ASP.NET中图片显示方法实例

作者:冰封的心 字体:[增加 减小] 来源:互联网 时间:2017-05-11

冰封的心通过本文主要向大家介绍了c asp.net实例,用实例学asp.net,ajax实例 asp.net,js调用asp.net方法,上传图片 asp.net等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了ASP.NET中图片的显示方法。分享给大家供大家参考。具体如下:

genimage.ashx:

genimage.ashx.cs:

// Copyright (C) 2003 by Greg Ennis
// (mailto:greg@ennis.net)
//
// The contents of this file are subject to the Artistic License (the "License").
// You may not use this file except in compliance with the License. 
// You may obtain a copy of the License at:
// http://www.opensource.org/licenses/artistic-license.html
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.IO;
using System.Configuration;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace netpix
{
  public class ImageGenerator : IHttpHandler 
  { 
    public bool IsReusable 
    { get { return true; } } 
    public void ProcessRequest(HttpContext Context) 
    { 
      // Get the image filename and album root path from the database
      //图片浏览次数
      int numviews;
      //图片数据库中的ID
      int picid = Convert.ToInt32(Context.Request["id"]);
      //图片路径 
      string imgpath = npdata.GetPathToPicture(picid, out numviews);
      // Writing an image to output stream
      Context.Response.ContentType = "image/jpg";
      // 'thumbnail' means we are requesting a thumbnail
      //显示缩略图
      if (Context.Request["thumbnail"] != null)
      {
        // Need to load the image, resize it, and stream to the client.
        // Calculate the scale so as not to stretch or distort the image.
        Bitmap bmp = new Bitmap(imgpath);
        float scale = 150.0f / System.Math.Max(bmp.Height, bmp.Width);
        System.Drawing.Image thumb = bmp.GetThumbnailImage((int)(bmp.Width * scale), (int)(bmp.Height * scale), null, System.IntPtr.Zero);
        thumb.Save(Context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
        bmp.Dispose();
        thumb.Dispose();
      }
      else
      {
        // Stream directly from the file
        // Get the stream and send it out the response
        System.IO.FileStream fs = File.Open(imgpath, FileMode.Open, FileAccess.Read, FileShare.Read);
        const int byteLength = 8192;
        byte[] bytes = new byte[byteLength];
        while( fs.Read(bytes, 0, byteLength ) != 0 )
        {
          Context.Response.BinaryWrite(bytes); 
        }
        fs.Close();
        //更新数据库浏览次数
        npdata.SetNumViews(picid, numviews+1);
      }
    }
  }
}

</div>

使用方法:

希望本文所述对大家的ASP.NET程序设计有所帮助。

</div>
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • ASP.NET数据库操作类实例
  • ASP.NET导出word实例
  • asp.net反射简单应用实例
  • ASP.NET中的C#基础知识
  • asp.net core mvc实现文件上传实例
  • ASP.NET Core 导入导出Excel xlsx 文件实例
  • Asp.net中安全退出时清空Session或Cookie的实例代码
  • asp.net保存网上图片到服务器的实例
  • asp.net多文件上传实例讲解
  • ASP.Net分页的分页导航实例

相关文章

  • 2017-05-11C#与.net高级编程 C#的多态介绍
  • 2017-05-11win7系统下 vs2010 调式就关闭要重启处理方法
  • 2017-05-11ASP.NET将文件写到另一服务器(图文教程)及注意事项
  • 2017-05-11ASP.NET 2.0中的数据操作之九:跨页面的主/从报表
  • 2017-05-11HTTP协议下用Web Service上传大文件的解决方案
  • 2017-05-11asp.net中List的使用方法
  • 2017-05-11学习使用ASP.NET 2.0的本地化
  • 2017-05-11VS2015开发环境的安装和配置
  • 2017-05-11.net中mshtml处理html的方法
  • 2017-05-11asp.net下UTF-7转GB2312编码的代码(中文)

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 详解GridView自带的编辑删除更新功能
    • asp.net 用XML生成放便扩展的自定义树
    • ASP.NET页面优化 性能提升8倍的方法
    • VS2012实现简单登录界面
    • .net调用JScript脚本及JS url加密解密
    • asp.net如何得到GRIDVIEW中某行某列值的方法
    • asp.net Javascript获取CheckBoxList的value
    • asp.net 无刷新附件上传实现方法
    • ASP.NET存储过程实现分页效果(三层架构)
    • ASP.NET数据绑定控件详解

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有