图片缩略技术.请教!! 把大于80*80的任何格式的图压成这种格式..不变形.且图是填充成整个img...可以看看http://photo.wangyou.com/这个..好像不是按比例压缩..而是取其中的一部分主要的生成新的缩略图.不知那位仁兄..做过..接触过...教教小弟..:)嘿嘿....... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用DataList做吧。我以前做过。里面放一下ImageButton,然后绑定当前列。发段源码你看看吧!! private void Binddata() {conn = new SqlConnection(ConfigurationSettings.AppSettings["Strcon"].ToString());string sql="select 'd:\\彩图\\'+ id + '.gif' as pic, id,type from pic where type='风光' order by ID Asc "; da = new SqlDataAdapter(sql,conn); ds = new DataSet(); try { //填充数据集 da.Fill(ds,"pic"); //创建分页类 PagedDataSource objPage = new PagedDataSource(); //设置数据源 objPage.DataSource = ds.Tables["pic"].DefaultView; //允许分页 objPage.AllowPaging = true; //设置每页显示的项数 objPage.PageSize = 12; //定义变量用来保存当前页索引 int CurPage; //判断是否具有页面跳转的请求 if (Request.QueryString["Page"] != null) CurPage=Convert.ToInt32(Request.QueryString["Page"]); else CurPage=1; //设置当前页的索引 objPage.CurrentPageIndex = CurPage-1; //显示状态信息 lblCurPage.Text = "当前页:第" + CurPage.ToString()+"页"; if(objPage.FirstIndexInPage!=0) first.NavigateUrl=Request.CurrentExecutionFilePath; //如果当前页面不是首页 if (!objPage.IsFirstPage) //定义"上一页"超级链接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引值 lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage-1); //如果当前页面不是最后一页 if (!objPage.IsLastPage) //定义"下一页"超级链接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引值 lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(CurPage+1); if(!objPage.IsLastPage) last.NavigateUrl=Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(CurPage=(objPage.PageCount)); //进行数据绑定 DataList1.DataSource = objPage; DataList1.DataBind(); lblcount.Text="总共" + Convert.ToInt32(ds.Tables[0].Rows.Count) + "条记录"; lblPageCount.Text="共"+objPage.PageCount+"页"; } catch(Exception err) { Response.Write(err.Message); } } <asp:datalist id="DataList1" runat="server" DataKeyField="id" CellSpacing="7" RepeatColumns="4" RepeatDirection="Horizontal" Width="456px" ShowHeader="False" ShowFooter="False" BorderColor="#660066" BorderStyle="None" BackColor="White" CellPadding="0" GridLines="Both" BorderWidth="1px" Height="160px" Font-Size="X-Small"> <SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle> <AlternatingItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></AlternatingItemStyle> <ItemStyle HorizontalAlign="Center" Height="10px" ForeColor="#330099" VerticalAlign="Middle"></ItemStyle> <ItemTemplate> <a href='javascript:win=window.open("<%# DataBinder.Eval(Container, "DataItem.id","tanchu.aspx?id={0}") %>","","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=365,height=400");win.focus();'> <asp:Image id=Image1 Width="101px" Height="80px" ImageUrl='<%# DataBinder.Eval(Container, "DataItem.pic") %>' Runat="server"> </asp:Image></a> <asp:Label id=Label1 runat="server" Width="68px" Height="1px" text='<%# DataBinder.Eval(Container, "DataItem.id") %>'> </asp:Label> </ItemTemplate> <FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle> <HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle></asp:datalist> public void pic_zero(string sourcepath,string aimpath,int scale) { string originalFilename =sourcepath; //生成的高质量图片名称 string strGoodFile =aimpath; //从文件取得图片对象 System.Drawing.Image image = System.Drawing.Image.FromFile(originalFilename); int iImgWidth = image.Width; int iImgHeight = image.Height; int iScale = (iImgWidth / scale)>(iImgHeight/scale) ? (iImgWidth / scale) : (iImgHeight / scale); //取得图片大小 System.Drawing.Size size = new Size(image.Width / iScale , image.Height / iScale); //新建一个bmp图片 System.Drawing.Image bitmap = new System.Drawing.Bitmap(size.Width,size.Height); //新建一个画板 System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap); //设置高质量插值法 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量,低速度呈现平滑程度 g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //清空一下画布 g.Clear(Color.Blue); //在指定位置画图 g.DrawImage(image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), new System.Drawing.Rectangle(0, 0, image.Width,image.Height), System.Drawing.GraphicsUnit.Pixel); //保存高清晰度的缩略图 bitmap.Save(strGoodFile, System.Drawing.Imaging.ImageFormat.Jpeg); g.Dispose(); image.Dispose(); } showing.aspx.csusing System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;using System.Drawing.Imaging;using System.Drawing.Drawing2D;namespace rabbit{/// <summary>/// showimg 的摘要说明。/// </summary>public class showimg : System.Web.UI.Page{private void Page_Load(object sender, System.EventArgs e){// 在此处放置用户代码以初始化页面Response.ContentType="image/jpeg";System.Drawing.Image img=System.Drawing.Image.FromFile("E:\\pictrue\\P1020075.JPG");//img.RotateFlip(RotateFlipType.Rotate90FlipNone);Bitmap bmp=new Bitmap(img,img.Width/20,img.Height/20);bmp.Save(Response.OutputStream,ImageFormat.Jpeg);}#region Web 窗体设计器生成的代码override protected void OnInit(EventArgs e){//// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。//InitializeComponent();base.OnInit(e);}/// <summary>/// 设计器支持所需的方法 - 不要使用代码编辑器修改/// 此方法的内容。/// </summary>private void InitializeComponent(){ this.Load += new System.EventHandler(this.Page_Load);}#endregion}}showing.aspx<%@ Page language="c#" Codebehind="showimg.aspx.cs" AutoEventWireup="false" Inherits="rabbit.showimg" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ><HTML><HEAD><title>showimg</title><meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1"><meta name="CODE_LANGUAGE" Content="C#"><meta name="vs_defaultClientScript" content="JavaScript"><meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"></HEAD><body MS_POSITIONING="GridLayout"><form id="Form1" method="post" runat="server"></form></body></HTML> 谢谢各位..我要的不是按比例压缩的技术.我要的是取图片其中一块..压成80*80的图片..不失真..不变形...可以看看http://photo.wangyou.com/这个..:) 我晕。你不会设那个image控件的width跟hight吗?????二个设为80*80就OK了。我也是这样设的!!!!!!!!!!!我全部页面代码都发给你了。 你说的那个也有好几种解决方式 style的clip就可以的.....非常之简单 我看了一下..唯有你写的是源码是DataList绑定..我要的是缩略源码...且不是按比例缩略..是取其中一个正方形...生成的新图..麻烦小猪妹.和huacha说详细一点可以吗??嘿嘿谢谢... <HTML><BODY><DIV STYLE="position:absolute;top:0;left:200;clip:rect(15px auto auto auto)"><IMG SRC="sphere.jpg"/></DIV><DIV STYLE="position:absolute;top:0;left:300;clip:rect(auto 15px auto auto)"><IMG SRC="sphere.jpg"/></DIV><DIV STYLE="position:absolute;top:0;left:400;clip:rect(auto auto 15px auto)"><IMG SRC="sphere.jpg"/></DIV><DIV STYLE="position:absolute;top:0;left:500;clip:rect(auto auto auto 15px)"><IMG SRC="sphere.jpg"/></DIV></BODY></HTML> 小猪妹..我用过你的方法拉..只是你这个还是用原图...只是显示其中的一部分我觉得这个方法不好..一点都没减轻服务器的压力..这个东东.肯定要用缩略图的...http://photo.wangyou.com/这个网站的图..都是75*75的..且是取图片中的一个正方形..我是想不到是怎么缩略的..不知有那位仁兄接解过..请教..嘿嘿 asp.net 网页验证码问题 asp.net引用谷歌地图,急请帮忙O(∩_∩)O谢谢 请推荐比较优秀的asp.net开源论坛以及CMS 一个初学者的问题 请教为什么点击html button 控件没有反应? 动态加载用户控件与静态加载的区别 怎样设置滚动条的着色 判断用户名重复的问题?? 誰能給講講 viewstate 如何在框架中的一个页面实现刷新整个框架的效果? 怎么样设置一下,让用户输入主机ip就自动访问主机的主页面的啊 高手请进,所指定的文件不是有效的SQL SERVER数据库文件,有谁碰到过吗?
{
conn = new SqlConnection(ConfigurationSettings.AppSettings["Strcon"].ToString());
string sql="select 'd:\\彩图\\'+ id + '.gif' as pic, id,type from pic where type='风光' order by ID Asc ";
da = new SqlDataAdapter(sql,conn);
ds = new DataSet();
try
{
//填充数据集
da.Fill(ds,"pic");
//创建分页类
PagedDataSource objPage = new PagedDataSource();
//设置数据源
objPage.DataSource = ds.Tables["pic"].DefaultView;
//允许分页
objPage.AllowPaging = true;
//设置每页显示的项数
objPage.PageSize = 12;
//定义变量用来保存当前页索引
int CurPage;
//判断是否具有页面跳转的请求
if (Request.QueryString["Page"] != null)
CurPage=Convert.ToInt32(Request.QueryString["Page"]);
else
CurPage=1;
//设置当前页的索引
objPage.CurrentPageIndex = CurPage-1;
//显示状态信息
lblCurPage.Text = "当前页:第" + CurPage.ToString()+"页";
if(objPage.FirstIndexInPage!=0)
first.NavigateUrl=Request.CurrentExecutionFilePath;
//如果当前页面不是首页
if (!objPage.IsFirstPage)
//定义"上一页"超级链接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引值
lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage-1);
//如果当前页面不是最后一页
if (!objPage.IsLastPage)
//定义"下一页"超级链接的URL为:当前执行页面的虚拟路径,并传递下一页面的索引值
lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(CurPage+1);
if(!objPage.IsLastPage)
last.NavigateUrl=Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(CurPage=(objPage.PageCount));
//进行数据绑定
DataList1.DataSource = objPage;
DataList1.DataBind();
lblcount.Text="总共" + Convert.ToInt32(ds.Tables[0].Rows.Count) + "条记录";
lblPageCount.Text="共"+objPage.PageCount+"页";
}
catch(Exception err)
{
Response.Write(err.Message);
}
}
RepeatDirection="Horizontal" Width="456px" ShowHeader="False" ShowFooter="False" BorderColor="#660066" BorderStyle="None" BackColor="White" CellPadding="0" GridLines="Both" BorderWidth="1px"
Height="160px" Font-Size="X-Small">
<SelectedItemStyle Font-Bold="True" ForeColor="#663399" BackColor="#FFCC66"></SelectedItemStyle>
<AlternatingItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></AlternatingItemStyle>
<ItemStyle HorizontalAlign="Center" Height="10px" ForeColor="#330099" VerticalAlign="Middle"></ItemStyle>
<ItemTemplate>
<a href='javascript:win=window.open("<%# DataBinder.Eval(Container, "DataItem.id","tanchu.aspx?id={0}") %>","","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=365,height=400");win.focus();'>
<asp:Image id=Image1 Width="101px" Height="80px" ImageUrl='<%# DataBinder.Eval(Container, "DataItem.pic") %>' Runat="server">
</asp:Image></a>
<asp:Label id=Label1 runat="server" Width="68px" Height="1px" text='<%# DataBinder.Eval(Container, "DataItem.id") %>'>
</asp:Label>
</ItemTemplate>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<HeaderStyle Font-Bold="True" ForeColor="#FFFFCC" BackColor="#990000"></HeaderStyle>
</asp:datalist>
{
string originalFilename =sourcepath;
//生成的高质量图片名称
string strGoodFile =aimpath; //从文件取得图片对象
System.Drawing.Image image = System.Drawing.Image.FromFile(originalFilename);
int iImgWidth = image.Width;
int iImgHeight = image.Height;
int iScale = (iImgWidth / scale)>(iImgHeight/scale) ? (iImgWidth / scale) : (iImgHeight / scale); //取得图片大小
System.Drawing.Size size = new Size(image.Width / iScale , image.Height / iScale);
//新建一个bmp图片
System.Drawing.Image bitmap = new System.Drawing.Bitmap(size.Width,size.Height);
//新建一个画板
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
//设置高质量插值法
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
//设置高质量,低速度呈现平滑程度
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
//清空一下画布
g.Clear(Color.Blue);
//在指定位置画图
g.DrawImage(image, new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
new System.Drawing.Rectangle(0, 0, image.Width,image.Height),
System.Drawing.GraphicsUnit.Pixel);
//保存高清晰度的缩略图
bitmap.Save(strGoodFile, System.Drawing.Imaging.ImageFormat.Jpeg);
g.Dispose();
image.Dispose();
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;namespace rabbit
{
/// <summary>
/// showimg 的摘要说明。
/// </summary>
public class showimg : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Response.ContentType="image/jpeg";System.Drawing.Image img=System.Drawing.Image.FromFile("E:\\pictrue\\P1020075.JPG");
//img.RotateFlip(RotateFlipType.Rotate90FlipNone);
Bitmap bmp=new Bitmap(img,img.Width/20,img.Height/20);bmp.Save(Response.OutputStream,ImageFormat.Jpeg);
}#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}showing.aspx<%@ Page language="c#" Codebehind="showimg.aspx.cs" AutoEventWireup="false" Inherits="rabbit.showimg" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>showimg</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
</form>
</body>
</HTML>
我要的是取图片其中一块..压成80*80的图片..不失真..不变形...
可以看看http://photo.wangyou.com/这个..
:)
<BODY>
<DIV STYLE="position:absolute;top:0;left:200;
clip:rect(15px auto auto auto)">
<IMG SRC="sphere.jpg"/>
</DIV>
<DIV STYLE="position:absolute;top:0;left:300;
clip:rect(auto 15px auto auto)">
<IMG SRC="sphere.jpg"/>
</DIV>
<DIV STYLE="position:absolute;top:0;left:400;
clip:rect(auto auto 15px auto)">
<IMG SRC="sphere.jpg"/>
</DIV>
<DIV STYLE="position:absolute;top:0;left:500;
clip:rect(auto auto auto 15px)">
<IMG SRC="sphere.jpg"/>
</DIV>
</BODY>
</HTML>
我觉得这个方法不好..一点都没减轻服务器的压力..这个东东.肯定要用缩略图的...http://photo.wangyou.com/这个网站的图..
都是75*75的..且是取图片中的一个正方形..我是想不到是怎么缩略的..不知有那位仁兄接解过..请教..嘿嘿