BGRABitmap/zh CN: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: BGRABitmap/zh CN
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ### 说明 | |
| 2 | + | ||
| 3 | + | **BGRABitmap** 是一个用来创建和更改透明图像(具有alpha 通道)的单元集. 直接像素访问允许进行快速的图像处理. 这个库已在 Windows, Ubuntu 和 Mac OS X 平台测试通过(最后的版本不能在 Mac平台工作), 以及各平台的小部件集 win32, gtk1, gtk2 和 carbon. | |
| 4 | + | ||
| 5 | + | 其中主要的类是 [[TBGRABitmap class|TBGRABitmap]], 派生自 [[fcl-image|TFPCustomImage]]. 还有一个类 [[TBGRAPtrBitmap class|TBGRAPtrBitmap]] 允许编辑已经分配的 BGRA 数据. 每个像素的格式包括4个字节 (顺序为 蓝, 绿, 红 和 alpha. | |
| 6 | + | ||
| 7 | + | ### 使用 BGRABitmap | |
| 8 | + | ||
| 9 | + | #### 教程 | |
| 10 | + | ||
| 11 | + | - [如何将应用从 TCanvas 转换到 BGRABitmap](http://www.youtube.com/watch?v=HGYSLgtYx-U) | |
| 12 | + | - [[BGRABitmap tutorial TAChart|使用 BGRABitmap渲染 TAChart]] | |
| 13 | + | - [[BGRABitmap tutorial|一系列入门教程]] | |
| 14 | + | - [LazPaint repository](http://lazpaint.svn.sourceforge.net/viewvc/lazpaint/)中的例子. | |
| 15 | + | ||
| 16 | + | #### 概述 | |
| 17 | + | ||
| 18 | + | 为了便于理解,函数的命名比较长. 其中的任何功能如函数或使用[[TBGRABitmap class|TBGRABitmap]]对象的属性都是容易理解的. 例如, 你可以使用CanvasBGRA作为画布,这和TCanvas类似 (但具有透明度和反锯齿),并且可以使用Canvas2D来实现类似 [HTML canvas](https://developer.mozilla.org/en/HTML:Canvas)的一些功能. | |
| 19 | + | ||
| 20 | + | 一些特定的功能需要依赖一些单元的引用, 但你可能不需要使用它们 : | |
| 21 | + | ||
| 22 | + | - TBGRAMultishapeFiller 实现多边形的反锯齿节点(交叉点),在 BGRAPolygon 单元中 | |
| 23 | + | - TBGRATextEffect 在 BGRATextFX 单元中 | |
| 24 | + | - 2D 转换在 BGRATransform 单元中 | |
| 25 | + | - TBGRAScene3D 在 BGRAScene3D 单元中 | |
| 26 | + | - 如果你需要用到层, BGRALayers 单元提供了 TBGRALayeredBitmap | |
| 27 | + | ||
| 28 | + | 双缓冲并不包含在 BGRABitmap 单元中, 因为其更多的是关于如何处理窗口. 如果要使用双缓冲技术, 你可以使用 TBGRAVirtualScreen ,包含在 [[BGRAControls]] 组件包中. 此外, BGRABitmap中双缓冲和其它任何缓冲用法一样. 你需要一个位图来存储你的绘图,然后使用一条绘图指令将其显示出来. | |
| 29 | + | ||
| 30 | + | #### 简单示例 | |
| 31 | + | ||
| 32 | + | 你必须在你的工程中引用 BGRABitmap 单元: | |
| 33 | + | ||
| 34 | + | ``` pascal | |
| 35 | + | Uses Classes, SysUtils, BGRABitmap, BGRABitmapTypes; | |
| 36 | + | ``` | |
| 37 | + | ||
| 38 | + | 单元 BGRABitmapTypes 包含所有必要的定义, 对于仅仅加载和显示位图,可以只声明引用 BGRABitmap. 然后, 首先创建一个 [[TBGRABitmap class|TBGRABitmap]] 对象: | |
| 39 | + | ||
| 40 | + | ``` pascal | |
| 41 | + | var bmp: TBGRABitmap; | |
| 42 | + | begin | |
| 43 | + | bmp := TBGRABitmap.Create(100,100,BGRABlack); //creates a 100x100 pixels image with black background | |
| 44 | + | ||
| 45 | + | bmp.FillRect(20,20,60,60,BGRAWhite, dmSet); //draws a white square without transparency | |
| 46 | + | bmp.FillRect(40,40,80,80,BGRA(0,0,255,128), dmDrawWithTransparency); //draws a transparent blue square | |
| 47 | + | end; | |
| 48 | + | ``` | |
| 49 | + | ||
| 50 | + | 最后显示位图: | |
| 51 | + | ||
| 52 | + | ``` pascal | |
| 53 | + | procedure TFMain.FormPaint(Sender: TObject); | |
| 54 | + | begin | |
| 55 | + | bmp.Draw(Canvas, 0, 0, True); // draw the bitmap in opaque mode (faster) | |
| 56 | + | end; | |
| 57 | + | ``` | |
| 58 | + | ||
| 59 | + | ### 概念 | |
| 60 | + | ||
| 61 | + | 位图中带有透明特性的像素被保存为4个值, 这里是4个字节,其顺序为 蓝, 绿, 红, Alpha. 最后一个通道定义了透明度 (0 代表 完全透明, 255 代表完全不透明), 其它通道定义了颜色和亮度. | |
| 62 | + | ||
| 63 | + | 基本上又两种绘图模式. 第一种是直接替换像素信息, 第二种是已有的像素和新的进行混合, 称为alpha通道混合. | |
| 64 | + | ||
| 65 | + | BGRABitmap 的函数提供4种模式: | |
| 66 | + | ||
| 67 | + | - dmSet : 替换绘制像素的4个字节, 不处理透明度 | |
| 68 | + | - dmDrawWithTransparency : 使用 alpha混合绘制并进行 gamma 矫正 (see below) | |
| 69 | + | - dmFastBlend or dmLinearBlend : 使用alpha混合绘制但不进行gamma矫正 (更快速 但会带有轻度的颜色畸变). | |
| 70 | + | - dmXor : 对个组件进行异或(Xor)操作,包括alpha (如果只反相颜色而保持alpha, 使用 BGRA(255,255,255,0) ) | |
| 71 | + | ||
| 72 | + | ### 集成的绘图功能 | |
| 73 | + | ||
| 74 | + | - 绘制/擦除 像素 | |
| 75 | + | - 画线(带或不带抗锯齿) | |
| 76 | + | - 浮点坐标 | |
| 77 | + | - 浮点画笔宽度 | |
| 78 | + | - 矩形 (边框 或 填充) | |
| 79 | + | - 椭圆 和 多边形 (带有抗锯齿) | |
| 80 | + | - 样条计算 (圆曲线) | |
| 81 | + | - 简单填充 (Floodfill) 或 渐进式填充 | |
| 82 | + | - 颜色渐变渲染 (线性, 放射...) | |
| 83 | + | - 圆角矩形 | |
| 84 | + | - 带透明特性的文本 | |
| 85 | + | ||
| 86 | + | ### 使用Canvas绘图 | |
| 87 | + | ||
| 88 | + | 开始使用一个*Canvas* 对象进行绘图, 使用通常的功能,但不具有反锯齿功能. 通过*CanvasOpacity* 属性定义绘制的透明度. 这张方法是很慢的,因为它需要进行图像转换. 如果你可以,改用 CanvasBGRA,它允许透明度和抗锯齿功能,同时与 TCanvas 具有相同的函数名。 | |
| 89 | + | ||
| 90 | + | ### 直接像素访问 | |
| 91 | + | ||
| 92 | + | 要想访问像素, 要用到两个属性, *Data* 和 *Scanline*. 前一个给出图像第一个像素的指针, 第二个给出指定行的第一个像素的指针. | |
| 93 | + | ||
| 94 | + | ``` pascal | |
| 95 | + | var | |
| 96 | + | bmp: TBGRABitmap; | |
| 97 | + | p: PBGRAPixel; | |
| 98 | + | n: integer; | |
| 99 | + | ||
| 100 | + | begin | |
| 101 | + | bmp := TBGRABitmap.Create('image.png'); | |
| 102 | + | p := bmp.Data; | |
| 103 | + | for n := bmp.NbPixels-1 downto 0 do | |
| 104 | + | begin | |
| 105 | + | p^.red := not p^.red; //反转 红色 通道 | |
| 106 | + | inc(p); | |
| 107 | + | end; | |
| 108 | + | bmp.InvalidateBitmap; //注意 这里我们直接访问像素 | |
| 109 | + | bmp.Draw(Canvas,0,0,True); | |
| 110 | + | bmp.Free; | |
| 111 | + | end; | |
| 112 | + | ``` | |
| 113 | + | ||
| 114 | + | 该例中,在后面调用*Draw*之前调用函数*InvalidateBitmap*来重建图像是有必要的. 注意行的顺序可以反转, 取决于*LineOrder* 属性. | |
| 115 | + | ||
| 116 | + | 另请参阅 [[Fast direct pixel access|直接像素访问方法]]. | |
| 117 | + | ||
| 118 | + | ### 图像处理 | |
| 119 | + | ||
| 120 | + | 可用滤镜 (prefixed with Filter) : | |
| 121 | + | ||
| 122 | + | - Radial blur : 非定向模糊 | |
| 123 | + | - Motion blur : 定向模糊 | |
| 124 | + | - Custom blur : 根据掩码模糊 | |
| 125 | + | ||
| 126 | + | - Median : 计算每个像素周围颜色的中位数,并具有边角柔化 | |
| 127 | + | - Pixelate : 用同色矩形简化图像 | |
| 128 | + | - Smooth : 柔化整个图像, complementary to Sharpen(锐化补充?) | |
| 129 | + | - Sharpen : 色彩锐化, complementary to Smooth(柔化补充?) | |
| 130 | + | ||
| 131 | + | - Contour : 在白色背景上绘制轮廓(像铅笔画) | |
| 132 | + | - Emboss : 绘制带阴影的轮廓 | |
| 133 | + | - EmbossHighlight : 绘制由灰度定义的所选内容的轮廓 | |
| 134 | + | ||
| 135 | + | - Grayscale : 将色彩转换为灰度值,带有gamma矫正 | |
| 136 | + | - Normalize : uses whole range of color luminosity 使用全域色彩亮度 | |
| 137 | + | ||
| 138 | + | - Rotate : 以一点为圆心旋转图像 | |
| 139 | + | - Sphere : 扭曲图像,使其看上去像在球体上的投影 | |
| 140 | + | - Twirl : 旋转扭曲图像 | |
| 141 | + | - Cylinder : 扭曲图像,使其看上去像在圆柱上的投影 | |
| 142 | + | - Plane : computes a high precision projection on a horizontal plane. This is quite slow. | |
| 143 | + | - SmartZoom3 : resizes the image x3 and detects borders, to have a useful zoom with ancient games sprites | |
| 144 | + | ||
| 145 | + | Some functions are not prefixed with Filter, because they do not return a newly allocated image. They modify the image in-place : | |
| 146 | + | ||
| 147 | + | - VerticalFlip : 垂直翻转图像 | |
| 148 | + | - HorizontalFlip : 水平翻转图像 | |
| 149 | + | - Negative : 负片 | |
| 150 | + | - LinearNegative : 负片,不带gamma矫正 | |
| 151 | + | - SwapRedBlue : 交换红色和蓝色通道 (在 BGRA 和 RGBA之间转换) | |
| 152 | + | - ConvertToLinearRGB : 从 sRGB 转换为 RGB. 注意,当使用dmDrawWithTransparency时,BGRABitmap用sRGB格式,而使用dmLinearBlend时,BGRABitmap用RGB格式. | |
| 153 | + | - ConvertFromLinearRGB : 从RGB转换为sRGB. | |
| 154 | + | ||
| 155 | + | ### 图像混合 | |
| 156 | + | ||
| 157 | + | PutImage is the basic image drawing function and BlendImage allows to combine images, like layers of image editing softwares. Available modes are the following: | |
| 158 | + | ||
| 159 | + | - LinearBlend : simple superimposition without gamma correction (equivalent to dmFastBlend) | |
| 160 | + | - Transparent : superimposition with gamma correction | |
| 161 | + | - Multiply : multiplication of color values (with gamma correction) | |
| 162 | + | - LinearMultiply : multiplication of color values (without gamma correction) | |
| 163 | + | - Additive : addition of color values (with gamma correction) | |
| 164 | + | - LinearAdd : addition of color values (without gamma correction) | |
| 165 | + | - Difference : difference of color values (with gamma correction) | |
| 166 | + | - LinearDifference : difference of color values (without gamma correction) | |
| 167 | + | - Negation : makes common colors disappear (with gamma correction) | |
| 168 | + | - LinearNegation : makes common colors disappear (without gamma correction) | |
| 169 | + | - Reflect, Glow : for light effects | |
| 170 | + | - ColorBurn, ColorDodge, Overlay, Screen : misc. filters | |
| 171 | + | - Lighten : keeps the lightest color values | |
| 172 | + | - Darken : keeps the darkest color values | |
| 173 | + | - Xor : exclusive or of color values | |
| 174 | + | ||
| 175 | + | These modes can be used in TBGRALayeredBitmap, which makes it easier because BlendImage only provides the basic blending operations. | |
| 176 | + | ||
| 177 | + | ### 屏幕快照 | |
| 178 | + | ||
| 179 | + |     | |
| 180 | + | ||
| 181 | + | ### 许可 | |
| 182 | + | ||
| 183 | + | 修改的 LGPL | |
| 184 | + | ||
| 185 | + | 作者: [Johann ELSASS](http://johann-elsass.net) ([Facebook](http://www.facebook.com/johann.elsass.1)) | |
| 186 | + | ||
| 187 | + | ### 下载 | |
| 188 | + | ||
| 189 | + | Latest version : <https://github.com/bgrabitmap/bgrabitmap/releases> | |
| 190 | + | ||
| 191 | + | Sourceforge 包含 [[LazPaint]] : <http://sourceforge.net/projects/lazpaint/files/src/> | |
| 192 | + | ||
| 193 | + | GitHub: <https://github.com/bgrabitmap/lazpaint/> | |
| 194 | + | ||
| 195 | + | --- | |
| 196 | + | *From the Free Pascal wiki, page "BGRABitmap/zh CN", as it stood on 2022-09-11 after a change by Circular, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
