在asp.net中对缩略图图像进行平方以得到高质量的图像 [英] Squaring thumnail image in asp.net with good quality image

查看:113
本文介绍了在asp.net中对缩略图图像进行平方以得到高质量的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...当我尝试对尺寸相等的图像进行正方形处理时,我正在使用图像的缩略图,它正在拉伸图像并且图像质量不佳,因此我希望图像尺寸等于75 * 75的图像缩略图和图像质量应该很好,请您帮忙....

我确实尝试了几个链接,但是图像变得张紧,图像质量不好...


在此先感谢您!!!

Hi... I am using thumnails of images when i am trying to square images with equal dimensions it is stretching image and the image quality is not good so i want an image thumnail with equal dimensions like 75 * 75 and the image quality should be good of that can u please help....

I did try few links but there image is getting streched and image quality not good...


Thanking you in advance!!

推荐答案

尝试一下
protected void UploadBtn_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(MapPath("~/Image/" + FileUpload1.FileName));
            System.Drawing.Image img1 = System.Drawing.Image.FromFile(MapPath("~/Image/") + FileUpload1.FileName);

            System.Drawing.Image bmp1 = img1.GetThumbnailImage(75, 75, null, IntPtr.Zero);
            bmp1.Save(MapPath("~/Thumbnail/") + FileUpload1.FileName);
            ThumbnailImage.ImageUrl = "~/Thumbnail/" + FileUpload1.FileName;
           
        }
    }



我已经使用了Image类的GetThumbnailImage方法.此方法返回给定原始图像的缩略图.我猜这可能是我们可以通过缩略图获得的最佳图像质量.



I have used GetThumbnailImage method of the Image class. This method returns the thumbnail image for the given original image.This could be the best picture quality we can derive with thumbnail i guess.


您的问题的第一个问题是:为什么75 x 75?对于所有源图像,它仅需要正方形长宽比,而事实并非如此.

您既可以同时保留单独的缩略图和全尺寸图像,也可以仅保留全尺寸图像,并即时生成或显示缩略图.

动态生成缩略图的方法有两种:1)显示以HTML比例缩小的原尺寸图像(由客户端重新采样),2)在服务器端按比例缩小它们.第一种方法需要更多的流量并浪费流量,这对于大图像而言可能是相当糟糕的;第二种方法浪费了额外的服务器端CPU时间,但将流量降到了最低.

主要原理只有一个:您只能对图像重新采样以缩小尺寸.除非您喜欢糟糕的画质,否则切勿尝试放大图像.


对于第一种方法,请使用HTML中的全尺寸图像,但指定显示图像的尺寸.您的Web浏览器将重新对图像进行采样.由于长宽比问题,请确保仅使用width或height属性,而不能同时使用两者:
First problem with your question is: why 75 x 75? It would require only square-like aspect ratio for all source images, which may not be the case.

You can either keep separate thumbnail and full-size images at the same time, or keep only the full-size images and generate or show thumbnails on the fly.

There are two approaches to the generation of thumbnails on the fly: 1) show full size images scaled down in HTML (re-sampling by the client), 2) scale them down on the server side. First approach needs more traffic and wastes traffic, which could be quite bad for big images; the second approach wastes extra server-side CPU time but minimized traffic.

The main principle is only one: you can re-sample images only to shrink the sizes. Never try to enlarge the images, unless you like lousy quality.


For first approach, use use full-size images in HTML, but specify the size of the displayed image. Your Web browser will re-sample the image down. Make sure to use only width or height attribute, not both, due to aspect ratio problem:
<img alt="some image" width="75" src="my-full-size-image.png" />


第二种方法基本上显示在解决方案1中,只需要对其进行检查即可解决长宽比问题.

—SA


The second approach is basically shown in Solution 1, only you need to review it to resolve the aspect ratio problem.

—SA


这篇关于在asp.net中对缩略图图像进行平方以得到高质量的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆