调整DataList ItemTemplate中的图像控件的大小 [英] Resizing Image control in DataList ItemTemplate
问题描述
我有一个DataList控件,在ItemTemplate中有一个Image控件。我想要调整进入该控件的图像大小。
我有一系列
的jpg文件,全尺寸,全分辨率(即大)。我有一个
数据库,其中包含对图片的引用。目前我必须手动调整jpgs的大小,然后使用数据绑定将ImageUrl属性指向jpg
。这很好用。我想避免调整大小步骤
并让服务器代码执行此操作。然后,如果用户请求,我可以将完整的图像加载到另一个浏览器窗口中,但是初始图像将是实际大小(640x480或720x480)。有没有办法用新的大小调整版替换数据主义中的
图像控件?
如果我在数据主义者ItemTemplate中有一个Button对象,我收到了被按下的
事件吗?只需在表单上按一下按钮,我就可以在IDE中点击控件并将事件添加到代码中。
I have a DataList control that has an Image control in the ItemTemplate. I
would like to resize the image that goes into that control. I have a series
of jpg files that are full size, full resolution (ie. large). I have a
database that contains references to the pictures. Currently I have to
resize the jpgs manually, and then point the ImageUrl property at that jpg
using databinding. This works fine. I would like to avoid the resizing step
and have the server code do it. I could then have the full image load into
another browser window if the user requests it, but the initial image would
be a realistic size (640x480 or 720x480). Is there a way to replace the
Image control in the datalist with a new resized one?
If I had a Button object in the datalist ItemTemplate, how do I receive the
event that it has been pressed? With just a button on the form, I can just
dblclick the control in the IDE and the event is added to the code.
推荐答案
David,
现在我假设你知道http协议的基本机制和
浏览器如何处理< img>,< link>,< script>标签等
所以理论上,你的图像控件的ImageUrl应该指向(保持简单)一个aspx页面,其唯一目的是:
给定全尺寸图像的url(作为参数),返回该图像的
缩略图。更好的是,如果你需要一个缩略图或全尺寸,url
中的一个额外参数会告诉它。
所以我要说的是ImageUrl属性图像控制看起来像
这个:
/ImageProcessor.aspx?filename=someimage.jpg&size=sm all
在ImageProcessor.aspx中没有你只需加载实际文件和(如果
size参数=小)得到一个缩略图。
你返回图像的方式(二进制)到浏览器是通过写入
Response.OutputStream
像这样的简单方法应该有帮助
stream在这种情况下Response.OutputStream。在我的情况下,宽度,高度和
img是我班级的私人成员,在
创建和实例时初始化。
public void GetThumbnail(ref System.IO.Stream stream)
{
System.Drawing.Image thumbnail;
>
System.IntPtr ptr = new IntPtr();
/ *如果width参数为0,则假定正常图像大小* /
if(width!= 0)
{
thumbnail = img.GetThumbnailImage(width,height,null ,ptr);
thumbnail.Save(stream,img.RawFormat);
thumbnail.Dispose();
< br $>
}
其他
{
img.Save( stream,img.RawFormat);
}
img.Dispose();
}
-
Shiv R. Kumar
http://www.matlus.com
" David W.西蒙兹" <哒*** @ simmonds.ca>在消息中写道
news:5jeOb.149615
David,
For now I will assume you know the basic mechanics of the http protocol and
how browsers work with regards to <img>, <link>, <script> tags etc.
So in theory, your image control''s ImageUrl should point to (to keep it
simple) an aspx page whose sole purpose is:
Given the url to the full sized image (as a parameter), to return the
thumbnail of that image. Better still, an additional parameter in the url
will tell it if you need a thumbnail or full size.
So lets say that the ImageUrl property of the image control would look like
this:
/ImageProcessor.aspx?filename=someimage.jpg&size=sm all
No in the ImageProcessor.aspx you simply load up the actual file and (if the
size parameter = small) get a thumbnail.
The way you return the "image" (binary) to the browser is by writing to the
Response.OutputStream
A simple method like this should help
"stream" in this case Response.OutputStream. In my case width, height and
img are private members of my class that were initialized at the time of
creating and instance.
public void GetThumbnail(ref System.IO.Stream stream)
{
System.Drawing.Image thumbnail;
System.IntPtr ptr = new IntPtr();
/* If the width parameter is "0", assume normal image size */
if (width != 0)
{
thumbnail = img.GetThumbnailImage(width, height, null, ptr);
thumbnail.Save(stream, img.RawFormat);
thumbnail.Dispose();
}
else
{
img.Save(stream, img.RawFormat);
}
img.Dispose();
}
--
Shiv R. Kumar
http://www.matlus.com
"David W. Simmonds" <da***@simmonds.ca> wrote in message
news:5jeOb.149615
ts4.20420@pd7tw3no ...
ts4.20420@pd7tw3no...
我有一个DataList控件, ItemTemplate中的图像控件。我想要调整进入该控件的图像的大小。我有一个
系列的jpg文件,它们是全尺寸,全分辨率(即大)。我有一个
数据库,其中包含对图片的引用。目前我必须手动调整jpgs的大小,然后使用数据绑定将ImageUrl属性指向该jpg
。这很好用。我想避免调整
步骤的大小并让服务器代码执行此操作。然后,如果用户请求,我可以将完整的图像加载到另一个浏览器窗口,但初始图像
将是一个真实的大小(640x480或720x480)。有没有办法用新的大小调整版本替换datalist中的
Image控件?
如果我在datalist ItemTemplate中有一个Button对象,我该怎么收到
它被按下的事件?只需在表单上按一下按钮,我就可以在IDE中点击控件并将事件添加到代码中。
I have a DataList control that has an Image control in the ItemTemplate. I
would like to resize the image that goes into that control. I have a series of jpg files that are full size, full resolution (ie. large). I have a
database that contains references to the pictures. Currently I have to
resize the jpgs manually, and then point the ImageUrl property at that jpg
using databinding. This works fine. I would like to avoid the resizing step and have the server code do it. I could then have the full image load into
another browser window if the user requests it, but the initial image would be a realistic size (640x480 or 720x480). Is there a way to replace the
Image control in the datalist with a new resized one?
If I had a Button object in the datalist ItemTemplate, how do I receive the event that it has been pressed? With just a button on the form, I can just
dblclick the control in the IDE and the event is added to the code.
嗨David,
感谢您使用MSDN新闻组。我是卢克,我正在审查这个问题
目前。据我了解,你有两个关于DataList的问题
控制:
1.如何调整图像大小
2。如何从ItemTemplate中的按钮接收事件
对于问题1,你可以参考Shiv的消息,我认为他的建议
是一个有效解决方案对于问题2,我们应该将按钮'的Click
事件与AddHandler方法的函数相关联。例如,在
datalist的'ItemDataBound:
Private Sub DataList1_ItemDataBound(ByVal sender As Object,ByVal e As
System.Web .UI.WebControls.DataListItemEventArgs)句柄
DataList1.ItemDataBound
Dim b As Button
b = e。 Item.FindControl(" MyButton")
AddHandler Button1.Click,AddressOf DataListButtonClick
End Sub
Private Sub DataListButtonClick(ByVal sender As System.Object,ByVal e
As System.EventArgs)处理Button1.Click
End Sub
希望这个帮助,
卢克
微软在线支持
安全! www.microsoft.com/security
(此帖子按原样提供,不作任何保证,并且不授予
权利。)
Hi David,
Thank you for using MSDN Newsgroup. I am Luke and I am review this issue
currently. As I understand, you have two questions about the DataList
control:
1. How to resize a image
2. How to receive events from a button in ItemTemplate
For question 1, you may refer to the Shiv''s message, I think his suggestion
is a valid solution. For question 2, we should associate the button''s Click
event with a function with AddHandler method. For example, in the
datalist''s ItemDataBound :
Private Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
DataList1.ItemDataBound
Dim b As Button
b = e.Item.FindControl("MyButton")
AddHandler Button1.Click, AddressOf DataListButtonClick
End Sub
Private Sub DataListButtonClick(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
End Sub
Hope this help,
Luke
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
这篇关于调整DataList ItemTemplate中的图像控件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!