定义无图片时显示默认图片,大小
2007-12-14 15:09
183 查看
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ImageThumbnail.ascx.cs" Inherits="ImageThumbnail" %>
<asp:Image ID="Image1" runat="server" CssClass="photo" BorderWidth="1" />
1using System;
2
3public partial class ImageThumbnail : System.Web.UI.UserControl
4
ImageFetch.ashx
1<%@ WebHandler Language="C#" Class="ImageFetch" %>
2
3using System;
4using System.Web;
5using System.Data.SqlClient;
6using System.Data;
7using System.IO;
8
9public class ImageFetch : IHttpHandler
10{
11 const int BUFFERSIZE = 1024;
12
13 public bool IsReusable
14 {
15 get
16 {
17 return true;
18 }
19 }
20
21 public void ProcessRequest(HttpContext context)
22 {
23 HttpResponse response = context.Response;
24 HttpRequest request = context.Request;
25 response.ContentType = "image/jpeg";
26 response.Cache.SetCacheability(HttpCacheability.Public);
27 response.BufferOutput = false;
28 writeSingleImage(Convert.ToInt32(request.QueryString["ImageID"]), Convert.ToInt32(request.QueryString["Size"]), response.OutputStream);
29 response.End();
30 }
31
32 public void writeSingleImage(int ImageID, int size, Stream output)
33 {
34 string cxnstr = System.Configuration.ConfigurationManager.ConnectionStrings["ClubSiteDB"].ConnectionString;
35 SqlConnection connection = new SqlConnection(cxnstr);
36 string query;
37 if (size == 0)
38 {
39 query = "select largeimage from images where id=@item_id";
40 }
41 else if (size == 1)
42 {
43 query = "select thumbimage from images where id=@item_id";
44 }
45 else if (size == 2)
46 {
47 query = "select origimage from images where id=@item_id";
48 }
49 else
50 {
51 query = "select largeimage from images where id=@item_id";
52 }
53 SqlCommand command = new SqlCommand(query, connection);
54 SqlParameter param0 = new SqlParameter("@item_id", SqlDbType.Int);
55 param0.Value = ImageID;
56 command.Parameters.Add(param0);
57 connection.Open();
58
59 byte[] d = ((byte[])(command.ExecuteScalar()));
60 output.Write(d, 0, d.Length);
61 connection.Close();
62 }
63}
<asp:Image ID="Image1" runat="server" CssClass="photo" BorderWidth="1" />
1using System;
2
3public partial class ImageThumbnail : System.Web.UI.UserControl
4
ImageFetch.ashx
1<%@ WebHandler Language="C#" Class="ImageFetch" %>
2
3using System;
4using System.Web;
5using System.Data.SqlClient;
6using System.Data;
7using System.IO;
8
9public class ImageFetch : IHttpHandler
10{
11 const int BUFFERSIZE = 1024;
12
13 public bool IsReusable
14 {
15 get
16 {
17 return true;
18 }
19 }
20
21 public void ProcessRequest(HttpContext context)
22 {
23 HttpResponse response = context.Response;
24 HttpRequest request = context.Request;
25 response.ContentType = "image/jpeg";
26 response.Cache.SetCacheability(HttpCacheability.Public);
27 response.BufferOutput = false;
28 writeSingleImage(Convert.ToInt32(request.QueryString["ImageID"]), Convert.ToInt32(request.QueryString["Size"]), response.OutputStream);
29 response.End();
30 }
31
32 public void writeSingleImage(int ImageID, int size, Stream output)
33 {
34 string cxnstr = System.Configuration.ConfigurationManager.ConnectionStrings["ClubSiteDB"].ConnectionString;
35 SqlConnection connection = new SqlConnection(cxnstr);
36 string query;
37 if (size == 0)
38 {
39 query = "select largeimage from images where id=@item_id";
40 }
41 else if (size == 1)
42 {
43 query = "select thumbimage from images where id=@item_id";
44 }
45 else if (size == 2)
46 {
47 query = "select origimage from images where id=@item_id";
48 }
49 else
50 {
51 query = "select largeimage from images where id=@item_id";
52 }
53 SqlCommand command = new SqlCommand(query, connection);
54 SqlParameter param0 = new SqlParameter("@item_id", SqlDbType.Int);
55 param0.Value = ImageID;
56 command.Parameters.Add(param0);
57 connection.Open();
58
59 byte[] d = ((byte[])(command.ExecuteScalar()));
60 output.Write(d, 0, d.Length);
61 connection.Close();
62 }
63}
相关文章推荐
- Python3 Tkinter基础 Label 让字体显示在图片的上方 设置字体颜色fg,字体字体大小font
- 解决图片显示比例匹配问题,我个人建议用js重新定义长宽
- JavaScript限定图片显示大小的方法
- 按指定大小显示图片
- 图片不存在,显示默认图片
- PlusSlider 2个焦点图,一个可以固定图片宽和高一个显示实际大小
- 图片加载失败显示默认图片
- ionic 图片加载失败,显示默认图片代替
- JS控制图片显示的大小(图片等比例缩放)
- C#的PictureBox显示图片与实际图片大小不符的解决办法
- Android应用程序当中GridView显示不同大小图片时Item挤出问题解决办法
- js动态加载显示图片,获取大小
- 同一张图片从res和Sd卡中读取显示大小不一样
- 处理用户上传图片大小不一,前台显示的问题
- JS控制图片显示的大小(图片等比例缩放)
- 开端——Glide加载图片至圆形控件上初次显示时是默认图片
- 使用jQuery动态改变图片显示大小
- 修改Magento se105模版 Latest Product等模块的默认图片及外框大小
- vue中的图片加载与显示默认图片
- JS控制图片显示的大小(图片等比例缩放)