- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试向 ImgView32 添加一个图层,并且我想在该图层上画一条线。但是,我希望该图层是透明的,因此它不会覆盖之前添加的所有图层。所以我想获得:
layer 1 -> image
layer 2 -> another image
layer 3 -> draw a line
layer 4 -> another image
这是一个问题:Delphi Graphics32 how to draw a line with the mouse on a layer您将在链接后面找到我用于绘制线条并声明 BitmapLayer 的代码。我不想在这里添加它,因此问题仍然很小。
顺便说一句,我已经尝试为绘图层声明这一点:
Bitmap.DrawMode := dmBlend;
BL.Bitmap.CombineMode:= cmMerge;
还有这个
Bitmap.DrawMode := dmTransparent;
BL.Bitmap.CombineMode:= cmMerge;
(BL -> TBitmapLayer)不用找了。当我创建 BitmapLayer 时,它就像一张白纸一样位于前面的图层之上,将它们隐藏起来。问题是:这可以做到吗(使图层透明)?那怎么办?
谢谢
最佳答案
这是基于之前测试的示例代码。也许这次最好发布整个单元,包括 .dfm。备忘录和按钮只是我通常测试设置的一部分,不需要演示 GR32。
首先是.dfm:
object Form5: TForm5
Left = 0
Top = 0
Caption = 'Form6'
ClientHeight = 239
ClientWidth = 581
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
OnDestroy = FormDestroy
DesignSize = (
581
239)
PixelsPerInch = 96
TextHeight = 13
object ImgView: TImgView32
Left = 8
Top = 8
Width = 320
Height = 220
Bitmap.ResamplerClassName = 'TNearestResampler'
BitmapAlign = baCustom
Color = clLime
ParentColor = False
Scale = 1.000000000000000000
ScaleMode = smScale
ScrollBars.ShowHandleGrip = True
ScrollBars.Style = rbsDefault
ScrollBars.Size = 17
OverSize = 0
TabOrder = 0
end
object Button1: TButton
Left = 380
Top = 8
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
end
object Memo: TMemo
Left = 380
Top = 39
Width = 185
Height = 187
Anchors = [akLeft, akTop, akRight, akBottom]
ScrollBars = ssVertical
TabOrder = 2
WordWrap = False
ExplicitHeight = 218
end
end
然后是.pas:
unit Unit5;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, GR32, GR32_Image, GR32_Layers, GR32_Backends;
type
TForm5 = class(TForm)
ImgView: TImgView32;
Button1: TButton;
Memo: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
FStartPoint, FEndPoint: TPoint;
FDrawingLine: boolean;
bm32: TBitmap32;
BL : TBitmapLayer;
FSelection: TPositionedLayer;
public
{ Public declarations }
procedure AddLineToLayer;
procedure SwapBuffers32;
procedure LayerMouseDown(Sender: TObject; Buttons: TMouseButton;Shift: TShiftState; X, Y: Integer);
procedure LayerMouseUp(Sender: TObject; Buttons: TMouseButton;Shift: TShiftState; X, Y: Integer);
procedure LayerMouseMove(Sender: TObject; Shift: TShiftState;X, Y: Integer);
procedure LayerOnPaint(Sender: TObject; Buffer: TBitmap32);
procedure SetSelection(Value: TPositionedLayer);
property Selection: TPositionedLayer read FSelection write SetSelection;
end;
var
Form5: TForm5;
implementation
{$R *.dfm}
var
imwidth: integer;
imheight: integer;
const
penwidth = 3;
pencolor = clBlue; // Needs to be a VCL color!
procedure TForm5.AddLineToLayer;
begin
bm32.Canvas.Pen.Color := pencolor;
bm32.Canvas.Pen.Width := penwidth;
bm32.Canvas.MoveTo(FStartPoint.X, FStartPoint.Y);
bm32.Canvas.LineTo(FEndPoint.X, FEndPoint.Y);
end;
procedure TForm5.FormCreate(Sender: TObject);
var
P: TPoint;
W, H: Single;
begin
imwidth := Form5.ImgView.Width;
imheight := Form5.ImgView.Height;
bm32 := TBitmap32.Create;
bm32.DrawMode := dmTransparent;
bm32.SetSize(imwidth,imheight);
bm32.Canvas.Pen.Width := penwidth;
bm32.Canvas.Pen.Color := pencolor;
with ImgView do
begin
Selection := nil;
Layers.Clear;
Scale := 1;
Scaled := True;
Bitmap.DrawMode := dmTransparent;
Bitmap.SetSize(imwidth, imheight);
Bitmap.Canvas.Pen.Width := penwidth;
Bitmap.Canvas.Pen.Color := clBlue;
Bitmap.Canvas.FrameRect(Rect(20, 20, imwidth-20, imheight-20));
Bitmap.Canvas.TextOut(15, 12, 'ImgView');
end;
BL := TBitmapLayer.Create(ImgView.Layers);
try
BL.Bitmap.DrawMode := dmTransparent;
BL.Bitmap.SetSize(imwidth,imheight);
BL.Bitmap.Canvas.Pen.Width := penwidth;
BL.Bitmap.Canvas.Pen.Color := pencolor;
BL.Location := GR32.FloatRect(0, 0, imwidth, imheight);
BL.Scaled := False;
BL.OnMouseDown := LayerMouseDown;
BL.OnMouseUp := LayerMouseUp;
BL.OnMouseMove := LayerMouseMove;
BL.OnPaint := LayerOnPaint;
except
BL.Free;
raise;
end;
FDrawingLine := false;
SwapBuffers32;
end;
procedure TForm5.FormDestroy(Sender: TObject);
begin
bm32.Free;
BL.Free;
end;
procedure TForm5.LayerMouseDown(Sender: TObject; Buttons: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
FStartPoint := Point(X, Y);
FDrawingLine := true;
// Memo.Lines.Add(Format('Start at x: %3d, y: %3d',[X, Y]))
end;
procedure TForm5.LayerMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if FDrawingLine then
begin
SwapBuffers32;
BL.Bitmap.Canvas.Pen.Color := pencolor;
BL.Bitmap.Canvas.MoveTo(FStartPoint.X, FStartPoint.Y);
BL.Bitmap.Canvas.LineTo(X, Y);
// Memo.Lines.Add(Format('Draw at x: %3d, y: %3d',[X, Y]))
end;
end;
procedure TForm5.LayerMouseUp(Sender: TObject; Buttons: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if FDrawingLine then
begin
FDrawingLine := false;
FEndPoint := Point(X, Y);
AddLineToLayer;
SwapBuffers32;
// Memo.Lines.Add(Format('End at x: %3d, y: %3d',[X, Y]))
end;
end;
procedure TForm5.LayerOnPaint(Sender: TObject; Buffer: TBitmap32);
begin
SwapBuffers32;
end;
procedure TForm5.SetSelection(Value: TPositionedLayer);
begin
if Value <> FSelection then
begin
FSelection := Value;
end;
end;
procedure TForm5.SwapBuffers32;
begin
// BitBlt(B.Bitmap.Canvas.Handle, 0, 0, B.Bitmap.Width, B.Bitmap.Height, bm32.Canvas.Handle, 0, 0, SRCCOPY);
// B.Bitmap.Draw(0, 0, bm32);
// bm32.DrawTo(B.Bitmap);
// BL.Bitmap := bm32;
TransparentBlt(
BL.Bitmap.Canvas.Handle, 0, 0, BL.Bitmap.Width, BL.Bitmap.Height,
bm32.Canvas.Handle, 0, 0, bm32.Width, bm32.Height, clWhite);
end;
end.
正如您从 .dfm 中看到的,我已将 ImgView 的背景设置为石灰色。我还画了一个矩形和一些文本来显示透明度。
在SwapBuffers中我尝试了TransparentBlt并且似乎有效。 Outcommented 也是直接将 bm32 分配给图层位图,这也可以,但可能并不总是您想要的。
关于Delphi Graphics32透明层画线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28534892/
我想知道如何在 OCaml 中设置文本大小。我尝试了 Graphics.set_text_size,我猜这应该可以解决问题。 但是无论我输入 set_text_size 200 还是 set_text
我想使用mathematica 为我正在写的书绘制图表。我想在mathematica中画一个图,将其保存为图片,然后将其导入到quarkxpress中,最后将其导出为pdf。 我的问题是最好使用哪种格
在顶层加载 Graphics 模块时,我收到一条错误消息“找不到 graphics.cma”。 我使用的是 OS X,而且我很确定我已经正确安装了 OCaml,因为我已经使用了大约一个月了。所以看起来
我知道 DDS 文件的存在,允许在 as/400 上对显示图形进行编程,但是还有其他方法吗? 具体来说,我想要做的是直接操作终端缓冲区,以便能够显示除文本之外的任何其他内容。例如,终端如下所示: 假设
Graphics.Save 与 Graphics.BeginContainer 有何不同? 最佳答案 看看here : The documentation does not differentiate
由于 Gdiplus::Graphics::DrawGraphics(Graphics*, x, y) 不存在,执行此类操作的最佳方法是什么? 例如,创建一个 Graphics 对象,使用各种 Dra
你能看出这有什么问题吗: (define (box d x1 y1 x2 y2) ( (graphics-draw-line d x1 y
我想编写一个 2D 游戏引擎。我遇到的问题(我不使用opengl之类的东西,所以我用cpu渲染)是,我通过graphics.drawImage()只得到7fps;您有任何加快速度的建议或其他替代方案吗
我在某些代码中发现了渲染错误,并找到了解决方法,但我想知道为什么我会得到不同的行为。在旧代码中,背景(有时)会呈现为白色,尽管在调试时 getBackground() 会返回正确的颜色。 旧代码: @
有谁知道是否有办法(也许通过外部API)将图形绘图/转换为多个图形?这个想法是同时保存 PNG 和 PDF(使用 Java IText 库)。 最佳答案 您可以将 Graphics 对象写入(java
我试图了解如何在英特尔芯片组上以 x86 保护模式绘制简单图形。我已经(有点)知道如何使用 VGA 接口(interface)来做到这一点,并且我正在尝试了解如何使用 G35 Express 来做到这
在我的应用程序中,我生成了一个条形码图像,该图像是根据用户使用 OpenFileDialog 上传的文件中的数据生成的。我的目标是允许用户在屏幕上查看条形码数据和图像本身,打印并使他们能够将两者保存为
我是 Java 新手,我只是想得到一些简单的东西,可能类似于 Zelle's graphics对于Python。 最佳答案 Java 类 Graphics和 Graphics2D应该包含 Zelle
如何将 FMX.Graphics.TBitmap 转换为 VCL.Graphics.TBitmap 或 Vcl.Imaging.PngImage.TPngImage? 我的项目中有FMX表单和VCL表
我需要找到用于间距目的的字体大小,发现这很有帮助:https://docs.oracle.com/javase/tutorial/2d/text/measuringtext.html 但是,我不确定如
我有一点奇怪的错误是由一个看似简单的问题引起的。 在我的源代码中,我尝试使用 QQuickPaintedItem 来呈现 QWidget 派生类 (QPushButton) 的整体外观,然后将其绘制到
我正在尝试通过具有以下规范的设备来解决 Android 应用程序崩溃的问题: Device PAP3400DUO 1 Manufacturer — Android version Android 4.
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
我有这行代码: mBgTransition = (TransitionDrawable) mSwitchBg.getBackground(); 背景曾经是一个常规的可绘制对象, 但现在是 9 个补丁
当我的应用程序在启动时崩溃时尝试实现自适应图标时出现此错误。 我无法想象为什么会收到此错误,因为在下面错误日志中提到的文件(MainActivity 和 BaseActivity)中,我没有使用Ada
我是一名优秀的程序员,十分优秀!