5.3.1 不透明度和透明度Opacity & Transparency
DrawImage方法也提供了三个算法选项来指定不透明度和透明度参数。The DrawImage method also provides three optional arguments to specify opacity and transparency parameters.
不指定这个参数按默认,一张图片是以完全不透明的方式被植入的。不透明度可以通过第四个可选参数被修改,它是一个0~1范围内的数值。数值0意味着这张图片是完全透明的,数值1则表示完全不透明。By default, an image being embedded is fully opaque (non-transparent). Opacity can be changed via the fourth optional argument which must be a number in the range 0 to 1. The value of 0 means the image is to be displayed fully transparent (invisible), and 1 fully opaque.
下列代码以50%的不透明度嵌入了一张图片。The following code embeds an image at 50% opacity:
Photo.Canvas.DrawImage 50, 20, Logo, 0.5
确保一张图片被放到另一张图片的上面时,它的象素能够被弄成透明。象素的颜色被弄成透明的方式是通过DrawImage方法的第五个可选参数来指定的。下面的代码使图片放到另一张图片上时,它的所有的红色象素透明。Certain pixels of an image can be made transparent when this image is placed on top of another image. The color of pixels to be made transparent is specified via the fifth argument of the DrawImage method. The following code makes all red pixels of an image transparent when displayed on top of another image:
Photo.Canvas.DrawImage 50, 20, Logo, , &HFF0000 ' opacity arg omitted
因为Jpeg使用有损压缩,象素颜色经常有轻微失真(尽管它不太可能被人眼察觉)。举例说明,一个象素的某种或者所有颜色成分在Jpeg压缩过程中可能从255变为254。为了适应这种不足,DrawMethod方法提供了另一种算法,通过算法5指定一个颜色转换偏差的允许值。这个数字必须在0到255之间,并同时影响组成一个象素的所有三种颜色。例如,以下代码改变了所有色彩在#16D636到#2AEA4A范围内的象素的透明度:Since JPEG uses lossy compression, pixel colors often get slightly distorted (although it may not be visible to the human eye). For example, one or all color components of a pixel may change from 255 (FF) to 254 during JPEG compression. To accommodate for this deficiency, the DrawImage method provides yet another argument, an allowable deviation from the color specified by argument 5. This number must be between 0 and 255 and affects all three color components of a pixel. For example, the following code turns transparent all pixels in the range #16D636 to #2AEA4A:
Photo.Canvas.DrawImage 50, 20, Logo, , #20E040, 10




上一篇
下一篇


文章来自:
Tags: 





