Delphi-Graphics32,以watermak的形式在JPG上绘制多个透明PNG [英] Delphi - Graphics32, draw multiple transparent PNG over JPG as watermak

查看:258
本文介绍了Delphi-Graphics32,以watermak的形式在JPG上绘制多个透明PNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在阅读Graphics32文档之后,我找不到使用层的令人讨厌的示例.

After read Graphics32 documentation I can't find a objetive example of use layers.

我只想撰写以下图像:

  • 第1层-背景图片(JPG)(800x600)
  • 第2层-透明的PNG作为框架边框(800x600)
  • 第3层-右下角具有25º旋转(90x90)的透明PNG

这是预期的结果:

// uses => GR32, GR32_Layers, GR32_Png, GR32_Image;
procedure TMain.Button1Click(Sender: TObject);
var
// src, dest: TPNGObject; <-- another frustrating try
// r: TRect;
   bmp: TBitmap32;
   png: TPortableNetworkGraphic32;
   rlayer: TCustomLayer;
   img1, img2, img3: TImgView32;
begin
   bmp := TBitmap32.Create;
   bmp.Assign(imgPreview.Picture); // TImage obj already have a JPG loaded

   img1 := TImgView32.Create(nil);
   img1.Bitmap := bmp;

   img2 := TImgView32.Create(nil);
   img2.Bitmap.LoadFromFile('C:\\layer2.png');

   img3 := TImgView32.Create(nil);
   img3.Bitmap.LoadFromFile('C:\\watermark.png');

   rlayer := TCustomLayer.Create(nil);
   rlayer.LayerCollection.Add(img1.Layers.Items[0]); // [DCC Error]  Incompatible types: 'TLayerClass' and 'TCustomLayer' ????

   ...

如何向收藏夹添加新图层?毕竟,我该如何保存呢?

How can I add a new layer to collection? And after all, how can I save this?

推荐答案

LayerCollection.Add方法期望接收类型为TLayerClass的值.也就是说,它想要接收 class ,而不是类的 instance .为了使编译器满意,可以按字面意思 TCustomLayer传递它;该集合将实例化给定的类本身.它将返回实例引用.在 GR32_Layers.pas .

The LayerCollection.Add method expects to receive a value of type TLayerClass. That is, it wants to receive the class, not an instance of a class. To satisfy the compiler, pass it literally TCustomLayer; the collection will instantiate the given class itself. It will return the instance reference. See for yourself in GR32_Layers.pas.

但是,开始时您使用了错误的方法. TBitmap32对象没有图层. TImage32组件具有图层,如果您不仅要一起显示多个位图图层,而且还允许用户与这些图层进行交互,则很有用.您可以使用HitTest方法检测到哪一层,如图层概述.每一层都包含一个图形;对于位图,您可能要使用TBitmapLayer,而不仅仅是TCustomLayer.

However, you're taking the wrong approach to begin with. TBitmap32 objects don't have layers. A TImage32 component has layers, which is useful if you want to not only display multiple bitmaps layers together, but also allow the user to interact with the layers; you'd detect which layer is which with the HitTest method, as described in the layer overview. Each layer consists of one graphic; for bitmaps, you probably want to use TBitmapLayer, not just TCustomLayer.

只需创建一个新的位图,就根本不需要图层. (并且,只要您使用的是能够理解PNG图像的Delphi版本,我就可以确定您甚至不需要Graphics32.)相反,只需从空白位图开始即可.将主位图绘制到需要的位置,然后绘制框架位图,然后绘制图章位图.最后,保存位图.

Just to create a new bitmap, you don't need layers at all. (And as long as you're using a Delphi version that understands PNG images, I'm pretty sure you don't even need Graphics32.) Instead, just start with a blank bitmap. Paint the main bitmap where it needs to go, then paint the frame bitmap, and then paint the stamp bitmap. Finally, save the bitmap.

除非您实际上要在表单上显示所有单独的位图,否则不需要这些TImgView32组件.该组件用于在屏幕上显示带有滚动条的图像.

Unless you're actually going to display all the separate bitmaps on a form, you don't need those TImgView32 components. That component is for displaying images on the screen with scroll bars.

这篇关于Delphi-Graphics32,以watermak的形式在JPG上绘制多个透明PNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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