【发布时间】:2011-10-20 09:59:47
【问题描述】:
我正在使用 Barcode Studio 2011 将 QR 码绘制到 Graphics32 - TImage32 组件中,我想将其保存为 png 格式,但白色是透明的,这是我在 Graphics32 的 OuterColor 中指定的。
OnFormCreate 我刚刚
procedure TForm1.FormCreate(Sender: TObject);
begin
psBarcodeComponent1.BarCode := 'some text here...';
end;
目前我已将绘画分配给按钮单击事件
procedure TForm1.Button8Click(Sender: TObject); // Paint the barcode
var
bmp: TBitmap32;
Coords: TRect;
begin
bmp := TBitmap32.Create;
bmp.SetSize(image.Width, image.Height);
bmp.Canvas.Brush.Color := color;
bmp.Canvas.Rectangle(-1, -1, image.Width+2, image.Height+2);
bmp.DrawMode := dmTransparent;
bmp.OuterColor := clWhite;
// make Coords the size of image
Coords := Rect(0,0,image.Width,image.Height);
psBarcodeComponent1.PaintBarCode(bmp.Canvas, Coords);
image.Bitmap.Assign(bmp);
end;
我正在使用 Vampyre Imaging Library 将位图转换为 PNG 格式,但我很乐意使用任何库、函数和建议 - 我已经尝试这样做将近一周了!我已经阅读并重新阅读了 graphics32 和 Vampyre Imaging Library 的文档,但我没有尝试将白色转换为透明颜色。我尝试过 clWhite、clWhite32 并将 drawMode 设置为 dmBlend 并应用 ChromaKey 函数都无济于事,但很沮丧,咖啡和一点啤酒也;)
这就是我保存它的方式...
procedure TForm1.Button7Click(Sender: TObject); // Save with Vampyre Imaging Lib
{ Try to save in PNG format with transparancy }
var
FImage: TSingleImage;
begin
FImage := TSingleImage.Create;
ConvertBitmap32ToImage(image.Bitmap, FImage);
FImage.SaveToFile('VampyreLibIMG.png');
end;
这会生成黑色缩略图,在 Windows 照片查看器中查看时它是完全透明的。
我希望我提供了足够的信息并且有人能够帮助我。
克里斯
【问题讨论】:
-
设置 bmp.transparentColor := clWhite; 时会发生什么而不是 bmp.outerColor := clWhite?
-
TBitmap32 中没有该成员 - 我也尝试从像素中选择 OuterColor 但它没有效果。 bmp.OuterColor := bmp.Pixel[0,1];
标签: image delphi png save transparency