第四章 图像处理Chapter 4: Image Manipulation
4.1 转换运算法则Resizing Algorithms
AspJpeg支持三种重分配图像象素的运算法则:邻近、两次线性、两次立方AspJpeg supports three popular image resizing algorithms: Nearest-Neighbor, Bilinear and Bicubic.
邻近方法是三者中运算最快的一种运算法则,但是生成的缩略图相对地比较低质。两次线性提供了较好的质量,但是生成速度比邻近慢两倍。而作为最后一种,两次立方,提供了最高的质量,但是生成速度大约比两次性线慢两倍,或者说,比邻近慢四倍。The Nearest-Neighbor algorithm is the fastest of the three, but produces relatively low-quality thumbnails. The Bilinear algorithm offers a much better quality but is about twice as slow as Nearest-Neighbor. And finally, the Bicubic algorithm provides the highest quality but is approximately twice as slow as Bilinear and, therefore, 4 times as slow as Nearest-Neighbor.
生成缩略图的转换算法可以通过属性Jpeg.Interpolation指定。这个属性的有效值分别是:0(邻近),1(两次线性),2(两次立方)。默认值是1(两次线性)。为了让这个属性生效,必须在调用Save、SendBinary或者Binary方法之前设置它。A resizing algorithm for your thumbnails can be specified via the property Jpeg.Interpolation. Valid values for this property are: 0 (Nearest-Neighbor), 1 (Bilinear), and 2 (Bicubic). The default value is 1 (Bilinear). For this property to take effect, it must be set before calling Save, SendBinary or Binary.
以下表格图示了设置这些插入属性的效果。注意与临近相比,双线性以及双立方产生的缩略图是多行平滑,也请注意在很多情况下,双立方提供了比立线性稍许更好的效果。The following table illustrates the effect of setting the Interpolation property. Notice how much smoother the thumbnails produced by the Bilinear and Bicubic algorithms are in comparison to Nearest-Neighbor. Notice also that in many cases (such as this one) Bicubic provides little, if any, improvement over Bilinear.
| Algorithm(jpeg.Interpolation) | Effect |
| 邻近Nearest Neighbor | ![]() |
| 两次线性Bilinear | ![]() |
| 两次立方Bicubic | ![]() |
4.2 图像锐化Image Sharpening
从1.1版本之后,AspJpeg通过Sharpen方法能够为转换的图片提供一个锐化滤镜。下面是一个规则的缩略图以及两个应用了不同的锐化级数的缩略图的展示:Starting with Version 1.1, AspJpeg is capable of applying a sharpening filter to an image being resized via the method Sharpen. A regular thumbnail and two thumbnails with various degrees of sharpening applied to them are shown below.
| No sharpening | Sharpen(1, 120) | Sharpen(1, 250) |
![]() | ![]() | ![]() |
Sharpen方法能够以两种算法使用它:半径锐化以及总量锐化。半径锐化控制以它为圆心The Sharpen method uses two Double arguments: Radius and Amount. Radius controls the size (in pixels) of an area around every pixel that the sharpening algorithm examines. This argument should normally be set to 1 or 2. Amount (expressed in %) specifies the degree of sharpness. This argument must be greater than 100.
For this property to take effect, it must be set before calling Save, SendBinary or Binary.
4.3 图像剪裁Image Cropping
AspJpeg1.1以上版本也能够将生成的缩略图剪除边框,或者说,剪裁它,通过调用Crop(x0, y0, x1, y1)方法。剪裁后图片AspJpeg 1.1+ is also capable of cutting off edges from, or cropping, the resultant thumbnails via the method Crop(x0, y0, x1, y1). The size of the cropped image is specified by the coordinates of the upper-left and lower-right corners within the resultant thumbnail, not the original large image.

If one or more coordinates passeed to the Crop method are outside the coordinate space of the image, this will actually expand the "canvas" around the image. The newly created empty area is filled with white color. This is useful, for example, if you need to create margins around the image. The following code creates a white 10-pixel margin around an image:
jpeg.Crop -10, -10, jpeg.Width + 10, jpeg.Height + 10





上一篇
下一篇








文章来自:
Tags: 





