图片显示失真的问题

XUXU_dragon 2009-07-28 11:11:42
各位大虾!

图片原来是有600的高和宽的,我想在网站上让它显示为120的高和宽,给它固定了高和宽之后,图片显示严重失真,很难看。


现在我想让图片缩小显小,但是不要失真,并且不能修改原图片,

注意:图片只是在显示的时候缩小,因为大图我以后还要用,

有没有什么办法可以解决啊,因为图片我己上传上去了现在最好是通过程序去实现,

各位大虾!小弟在此谢过了!
...全文
144 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
绿绦 2009-07-28
  • 打赏
  • 举报
回复
[Quote=引用楼主 xuxu_dragon 的回复:]
各位大虾!

图片原来是有600的高和宽的,我想在网站上让它显示为120的高和宽,给它固定了高和宽之后,图片显示严重失真,很难看。

[/Quote]

在 图片缩小显示的地方 你只控制显示小图的一个属性就是宽度

然后在你的图片外面加div 这个div的宽度也是你的这个宽度 在这个div加一个样式
style=" overflow:hidden"
就可以了赛 不失真 只是看不完


绿绦工作室 http://www.lvtaostudio.com

bigmingming 2009-07-28
  • 打赏
  • 举报
回复
using System;
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Text.RegularExpressions;

/// <summary>
// 图片处理。
// http://www.hulaka.com/
// (c) 2008 Dao
/// </summary>
public class Image
{
/// <summary>
/// 缩略模式。
/// </summary>
public enum ThumbMode : byte
{
/// <summary>
/// 完整模式
/// </summary>
Full = 1,
/// <summary>
/// 最大尺寸
/// </summary>
Max
}

/// <summary>
/// 缩略图。
/// </summary>
/// <param name="image">要缩略的图片</param>
/// <param name="size">要缩放的尺寸</param>
/// <param name="mode">缩略模式</param>
/// <param name="contentAlignment">对齐方式</param>
/// <returns>返回已经缩放的图片。</returns>
public static Bitmap Thumbnail(Bitmap image, Size size, ThumbMode mode, ContentAlignment contentAlignment)
{
if (!size.IsEmpty && !image.Size.IsEmpty && !size.Equals(image.Size))
{
//先取一个宽比例。
double scale = (double)image.Width / (double)size.Width;
//缩略模式
switch (mode)
{
case ThumbMode.Full:
if (image.Height > image.Width)
scale = (double)image.Height / (double)size.Height;
break;
case ThumbMode.Max:
if (image.Height / scale < size.Height)
scale = (double)image.Height / (double)size.Height;
break;
}
SizeF newSzie = new SizeF((float)(image.Width / scale), (float)(image.Height / scale));
Bitmap result = new Bitmap(size.Width, size.Height);
using (Graphics g = Graphics.FromImage(result))
{
g.FillRectangle(Brushes.White, new Rectangle(new Point(0, 0), size));
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.SmoothingMode = SmoothingMode.HighQuality;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.CompositingMode = CompositingMode.SourceOver;
g.CompositingQuality = CompositingQuality.HighQuality;
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
//对齐方式
RectangleF destRect;
switch (contentAlignment)
{
case ContentAlignment.TopCenter:
destRect = new RectangleF(new PointF(-(float)((newSzie.Width - size.Width) * 0.5), 0), newSzie);
break;
case ContentAlignment.TopRight:
destRect = new RectangleF(new PointF(-(float)(newSzie.Width - size.Width), 0), newSzie);
break;
case ContentAlignment.MiddleLeft:
destRect = new RectangleF(new PointF(0, -(float)((newSzie.Height - size.Height) * 0.5)), newSzie);
break;
case ContentAlignment.MiddleCenter:
destRect = new RectangleF(new PointF(-(float)((newSzie.Width - size.Width) * 0.5), -(float)((newSzie.Height - size.Height) * 0.5)), newSzie);
break;
case ContentAlignment.MiddleRight:
destRect = new RectangleF(new PointF(-(float)(newSzie.Width - size.Width), -(float)((newSzie.Height - size.Height) * 0.5)), newSzie);
break;
case ContentAlignment.BottomLeft:
destRect = new RectangleF(new PointF(0, -(float)(newSzie.Height - size.Height)), newSzie);
break;
case ContentAlignment.BottomCenter:
destRect = new RectangleF(new PointF(-(float)((newSzie.Width - size.Width) * 0.5), -(float)(newSzie.Height - size.Height)), newSzie);
break;
case ContentAlignment.BottomRight:
destRect = new RectangleF(new PointF(-(float)(newSzie.Width - size.Width), -(float)(newSzie.Height - size.Height)), newSzie);
break;
default:
destRect = new RectangleF(new PointF(0, 0), newSzie);
break;
}
g.DrawImage(image, destRect, new RectangleF(new PointF(0F, 0F), image.Size), GraphicsUnit.Pixel);
image.Dispose();
}
return result;
}
else
return image;
}

/// <summary>
/// 保存图片。
/// </summary>
/// <param name="image">要保存的图片</param>
/// <param name="quality">品质(1L~100L之间,数值越大品质越好)</param>
/// <param name="filename">保存路径</param>
public static void SaveIamge(Bitmap image, long quality, string filename)
{
using (EncoderParameters encoderParams = new EncoderParameters(1))
{
using (EncoderParameter parameter = (encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, quality)))
{
ImageCodecInfo encoder = null;
//取得扩展名
string ext = Path.GetExtension(filename);
if (string.IsNullOrEmpty(ext))
ext = ".jpg";
//根据扩展名得到解码、编码器
foreach (ImageCodecInfo codecInfo in ImageCodecInfo.GetImageEncoders())
{
if (Regex.IsMatch(codecInfo.FilenameExtension, string.Format(@"(;|^)\*\{0}(;|$)", ext), RegexOptions.IgnoreCase))
{
encoder = codecInfo;
break;
}
}
Directory.CreateDirectory(Path.GetDirectoryName(filename));
image.Save(filename, encoder, encoderParams);
}
}
}

/// <summary>
/// 保存图片。
/// </summary>
/// <param name="stream">要保存的流</param>
/// <param name="quality">品质(1L~100L之间,数值越大品质越好)</param>
/// <param name="filename">保存路径</param>
public static void SaveIamge(Stream stream, long quality, string filename)
{
using (Bitmap bmpTemp = new Bitmap(stream))
{
SaveIamge(bmpTemp, quality, filename);
}
}
}
bigmingming 2009-07-28
  • 打赏
  • 举报
回复
http://download.csdn.net/source/565319
chenwei175528 2009-07-28
  • 打赏
  • 举报
回复
看看js怎么操作图片放大缩小的
bigmingming 2009-07-28
  • 打赏
  • 举报
回复
http://download.csdn.net/source/1260148

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧