一个星期都没有解决的问题:如何对pictureBox中图片高质量的缩放
各位好,问题如下:将远程图片加载到本地的pictureBox中的Image里面,当在本地点击放大或者缩小按钮时,picturebox中的图片能相应地缩小或者放大(想要实现的效果就像WINDOWS系统自带的图片和传真查看器),最好能有实例代码
最近在网上找了很多关于pictureBox的问题,结果都不能令人满意
请问这个要这么解决? --------------------编程问答-------------------- 是否这种效果
<HTML>
<BODY>
<style>
a {
color: gray;
text-decoration: none;
}
a:hover {
color: #FF6600;
border-bottom: 1px dashed #666;
text-decoration: none;
}
</style>
<script>
function zoomimg(o)
{
var zoom=parseInt(o.style.zoom, 10)||100;
zoom+=event.wheelDelta/12;if (zoom>0&&zoom<=500) o.style.zoom=zoom+'%';
zoomvl.innerText=o.style.zoom;
return false;
}
function zoombig(o)
{
var zoom=parseInt(o.style.zoom, 10)||100;
zoom+=10;
if(zoom>0&&zoom<=500)
o.style.zoom=zoom+'%';
zoomvl.innerText=o.style.zoom;
return false;
}
function zoomsmall(o)
{
var zoom=parseInt(o.style.zoom, 10)||100;
zoom-=10;
if (zoom>0&&zoom<=500)
o.style.zoom=zoom+'%';
zoomvl.innerText=o.style.zoom;
return false;
}
</script>
<table width="100%" border="0" style="font-family: georgia,Tahoma;font-size: 9pt;">
<tr>
<td height="300" align="center" valign=top bgcolor="#FFFFFF">
在相应区域上下滚动鼠标滚轮可以放大缩小图片或文本,当前比例:<span style="color:#FF9900" id='zoomvl'>100%</span>
<div id=thetext style="font-family: georgia,Tahoma;" onmousewheel='return zoomimg(this)'>可以用鼠标滑轮进行缩放控制的文本</div><P><a href='#' onClick="zoombig(thetext)">『放大10%』</a>
<a href='#' onClick="zoomsmall(thetext)">『缩小10%』</a>
<a href='#' onClick="thetext.style.zoom='100%';zoomvl.innerText='100%';">『恢复100%』</a><BR>
<a href="#"><img src='C:\Documents and Settings\hong\My Documents\My Pictures\1680GameCar_1001.jpg' id='thephoto' border='0' onmousewheel='return zoomimg(this)' alt='可以缩放的图片'></a><P><a href='#' onClick="zoombig(thephoto)">『放大10%』</a>
<a href='#' onClick="zoomsmall(thephoto)">『缩小10%』</a>
<a href='#' onClick="thephoto.style.zoom='100%';zoomvl.innerText='100%';">『恢复100%』</a></td>
</tr>
</table>
</BODY>
</HTML>
--------------------编程问答-------------------- private void Form1_Paint(object sender, System.Windows.Form.PaintEventArgs e)
{
Graphics g = e.Graphics;
g.InterpolationMode = InterpolationMode.HighQualityBicublic;
Bitmap bmp = new Bitmap("XXX.jpg");
g.DrawImage(bmp, this.ClientRectangle);
}
用Form做最简单 --------------------编程问答-------------------- to huo789(四火)
先谢谢了,可能是我没有表达清楚,我的意思是用本地的WINDOWS窗体中有PICTURE来做,不是aspx来做 --------------------编程问答-------------------- 简单的做法就是PictureBox大小跟随图片大小变化,,
设置SizeMode为PictureBoxSizeMode.StretchImage
图片放大的时候PictureBox也放大,,图片缩小的时候PictureBox也缩小,, --------------------编程问答-------------------- 图像一旦缩放,显示质量就会下降,只有图像与显示器像素重合时效果最好 --------------------编程问答-------------------- 可以想着用算法对图象进行插值
网上有专门的算法,不过图象如果插的过大,速度上会比较慢,而且效果不好,马赛克出现
--------------------编程问答-------------------- 怎么没有解决办法吗? --------------------编程问答-------------------- pictureBox 本身不就有这个属性吗? --------------------编程问答-------------------- 帮你顶顶 --------------------编程问答-------------------- 给你个方法你试试吧
/// <summary>
/// 图片缩放
/// </summary>
/// <param name="bmpFile">图片地址</param>
/// <param name="bmpWidth">图片的新宽</param>
/// <param name="bmpHeight">图片的新高</param>
/// <returns>缩放的图片</returns>
public static Bitmap BitMapZoom(string bmpFile, int bmpWidth, int bmpHeight)
{
Bitmap zoomBmp, bmp;
try
{
bmp = new Bitmap(bmpFile);
zoomBmp = new Bitmap(bmpWidth, bmpHeight);
Graphics g = Graphics.FromImage(zoomBmp);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(bmp, new Rectangle(0, 0, bmpWidth, bmpHeight), new Rectangle(0, 0, bmp.Width, bmp.Height), GraphicsUnit.Pixel);
return zoomBmp;
}
catch
{ }
finally
{
bmp = null;
zoomBmp = null;
}
return null;
}
补充:.NET技术 , C#