AggPas Delphi 绘图透明度

发布于 2024-09-10 01:50:40 字数 3876 浏览 6 评论 0 原文

我想要做什么

我有一个绘图程序(它有效),它绘制位图“OBJmap”,然后将 OBJmap 放入 Wholemap 中。这一切都有效,但有一个问题。即使 objmap 和 Wholemap 设置为 PF32Bit,它似乎仍将 objmap 的未定义部分视为白色,因此当它将 objmap 放入 Wholemap 时,我在粘贴的图像后面会出现一个白色框,该图像应该是透明的。

这种情况只发生在 ATI 机器上,但这是针对学校的,他们都有 100% ati,因为它们很便宜(我不是有偏见),所以建议我使用 AggPas 来解决这个问题。

我的代码

procedure DrawScene();
var
  ObjLength,LineLength,Filllength,Obj,lin,angle,i,x1,y1,x2,y2:integer;
  Npoints : array[0..1] of Tpoint;
  WG,OG: Tagg2d;

  Objmap,wholemap:TBitmap;
begin
  //Set up WholeMap Bitmap
  wholemap := TBitmap.Create;
  wholemap.PixelFormat:=pf32bit;
  wholemap.Transparent:=false;
  wholemap.Width:=area;
  wholemap.height:=area;

  WG:= Tagg2d.create;
  BitmapAlphaTransparency(wholemap, 0);
  WG.attach(wholemap,False);
  WG.ClearAll(255,0,0,255);
  //BitmapAlphaTransparency(wholemap, 255);

  //WG.MasterAlpha(255);

  // itterate through each object drawing the object to OBJmap
  ObjLength:=length(Objects);
  for Obj:=0 to (ObjLength-1) do
  if objects[Obj].Visible then
  begin
    //Set up Object map Bitmap
    Objmap := TBitmap.Create;
    Objmap.PixelFormat:=pf32bit;

    Objmap.Transparent:=true;
    Objmap.Width:=Objects[obj].Boundright-objects[obj].Boundleft+3;
    Objmap.height:=Objects[obj].BoundTop-objects[obj].Boundbottom+3;

    OG:= Tagg2d.create;
    OG.attach(Objmap,False);

    {OG.ClearAll(0,0,255,255);  // Clears all bitmap to transparrent
    OG.MasterAlpha(255);
    OG.LineWidth(5);
    og.AntiAliasGamma(255);
    OG.
    OG.LineColor(0,255,0,255);
    OG.FillColor(0,255,0,255);
    //OG.
    OG.MoveTo(0,0);
    OG.LineTo(Objmap.width-1,Objmap.height-1); }

    //Draw the Lines to Objmap
    LineLength:=length(objects[Obj].Lines)-1;
    angle:=objects[Obj].Rotation;
    for lin:=0 to (LineLength) do
    begin
      //Transform points
      for i:=0 to 1 do
        Npoints[i] := PointAddition(RotatePoint(objects[obj].Lines[lin].Point[i],angle),point(-objects[obj].boundleft,-Objects[obj].Boundbottom),false);
      //draw transformed points
      Objmap:=DrawLine(Npoints[0].x,Npoints[0].y,Npoints[1].x,Npoints[1].y,objects[obj].Lines[lin].Color,Objmap,OG);
    end;
    //Draw the Fills to Objmap
    Filllength:=length(objects[Obj].Fills)-1;
    for i:=0 to Filllength do
    begin
      //transform points
      Npoints[0]:=PointAddition(RotatePoint(objects[Obj].Fills[i].Point,objects[Obj].Rotation),point(-objects[obj].boundleft,-Objects[obj].Boundbottom),false);
      // fill points
      Objmap:=fillpoint( Npoints[0].x, Npoints[0].y,objects[Obj].Fills[i].color,Objmap);
    end;

    //draw objmap to wholemap
    x1:=objects[obj].Position.x+objects[obj].Boundleft-1;
    y1:=area-(objects[obj].Position.y+objects[obj].Boundtop)-2;
    x2:=x1+Objmap.Width;
    y2:=y1+Objmap.Height;

    WG.TransformImage(Objmap,x1,y1,x2,y2);  //this show border
    //WG.copyimage(Objmap,x1,y1);  //this draws the scene up but does not handle transparencies correctly
    //wholemap.Canvas.Draw(x1,y1,Objmap);//does not work in PF32bit or on ati machines


    //wg.Free; // this it does not like (crash) do i need it?
    Objmap.Free;
  end;


   // write wholemap to Visible Canvas
   mainwindow.bufferim.Canvas.Draw(0,0,wholemap);
   wholemap.Free;
   mainwindow.RobotArea.Picture.Graphic:=mainwindow.bufferim.Picture.Graphic;
end;

图像示例

分别为“不工作”、“工作”和“当前”

替代文本 alt text

我只能使用默认

wholemap.Canvas.Draw

方法在 Nvidia 机器上获得工作结果,我希望让它在所有使用 aggpass 的机器上工作。

我该怎么办,如何将 objmap 绘制到整个地图上,但不绘制透明位?

What im trying to do

I have a drawing procedure (it works) it draws to a bitmap "OBJmap" it then puts OBJmap into Wholemap. This all works but there is a issue. It seems to treat the undefined parts of objmap as white even though objmap and wholemap is set as PF32Bit, and hence when it puts objmap into wholemap I get a white box behind the pasted image that should be transparent.

This only happens on ATI machines, but this is for schools and they all have 100% ati because they are cheap (im not biased honest), so I was recommended to use AggPas to solve this issue.

My code

procedure DrawScene();
var
  ObjLength,LineLength,Filllength,Obj,lin,angle,i,x1,y1,x2,y2:integer;
  Npoints : array[0..1] of Tpoint;
  WG,OG: Tagg2d;

  Objmap,wholemap:TBitmap;
begin
  //Set up WholeMap Bitmap
  wholemap := TBitmap.Create;
  wholemap.PixelFormat:=pf32bit;
  wholemap.Transparent:=false;
  wholemap.Width:=area;
  wholemap.height:=area;

  WG:= Tagg2d.create;
  BitmapAlphaTransparency(wholemap, 0);
  WG.attach(wholemap,False);
  WG.ClearAll(255,0,0,255);
  //BitmapAlphaTransparency(wholemap, 255);

  //WG.MasterAlpha(255);

  // itterate through each object drawing the object to OBJmap
  ObjLength:=length(Objects);
  for Obj:=0 to (ObjLength-1) do
  if objects[Obj].Visible then
  begin
    //Set up Object map Bitmap
    Objmap := TBitmap.Create;
    Objmap.PixelFormat:=pf32bit;

    Objmap.Transparent:=true;
    Objmap.Width:=Objects[obj].Boundright-objects[obj].Boundleft+3;
    Objmap.height:=Objects[obj].BoundTop-objects[obj].Boundbottom+3;

    OG:= Tagg2d.create;
    OG.attach(Objmap,False);

    {OG.ClearAll(0,0,255,255);  // Clears all bitmap to transparrent
    OG.MasterAlpha(255);
    OG.LineWidth(5);
    og.AntiAliasGamma(255);
    OG.
    OG.LineColor(0,255,0,255);
    OG.FillColor(0,255,0,255);
    //OG.
    OG.MoveTo(0,0);
    OG.LineTo(Objmap.width-1,Objmap.height-1); }

    //Draw the Lines to Objmap
    LineLength:=length(objects[Obj].Lines)-1;
    angle:=objects[Obj].Rotation;
    for lin:=0 to (LineLength) do
    begin
      //Transform points
      for i:=0 to 1 do
        Npoints[i] := PointAddition(RotatePoint(objects[obj].Lines[lin].Point[i],angle),point(-objects[obj].boundleft,-Objects[obj].Boundbottom),false);
      //draw transformed points
      Objmap:=DrawLine(Npoints[0].x,Npoints[0].y,Npoints[1].x,Npoints[1].y,objects[obj].Lines[lin].Color,Objmap,OG);
    end;
    //Draw the Fills to Objmap
    Filllength:=length(objects[Obj].Fills)-1;
    for i:=0 to Filllength do
    begin
      //transform points
      Npoints[0]:=PointAddition(RotatePoint(objects[Obj].Fills[i].Point,objects[Obj].Rotation),point(-objects[obj].boundleft,-Objects[obj].Boundbottom),false);
      // fill points
      Objmap:=fillpoint( Npoints[0].x, Npoints[0].y,objects[Obj].Fills[i].color,Objmap);
    end;

    //draw objmap to wholemap
    x1:=objects[obj].Position.x+objects[obj].Boundleft-1;
    y1:=area-(objects[obj].Position.y+objects[obj].Boundtop)-2;
    x2:=x1+Objmap.Width;
    y2:=y1+Objmap.Height;

    WG.TransformImage(Objmap,x1,y1,x2,y2);  //this show border
    //WG.copyimage(Objmap,x1,y1);  //this draws the scene up but does not handle transparencies correctly
    //wholemap.Canvas.Draw(x1,y1,Objmap);//does not work in PF32bit or on ati machines


    //wg.Free; // this it does not like (crash) do i need it?
    Objmap.Free;
  end;


   // write wholemap to Visible Canvas
   mainwindow.bufferim.Canvas.Draw(0,0,wholemap);
   wholemap.Free;
   mainwindow.RobotArea.Picture.Graphic:=mainwindow.bufferim.Picture.Graphic;
end;

Image examples

Not working ,Working and ,current respectivly

alt text
alt text
alt text

I am only able to get working result on Nvidia machines with the default

wholemap.Canvas.Draw

Method and I wish to get it to work on all machines using aggpass.

What do I do how do I draw objmap onto wholemap but not draw the transparent bits?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦途 2024-09-17 01:50:40

我遇到了同样的问题,您需要在调用 Transform Image 之前设置 BlendMode

WG.BlendMode(AGG_BlendSrcTop);

这对我有用,但您可能需要尝试几种混合模式才能获得正确的答案。

I had the same problem, you need to set the BlendMode before calling Transform Image

WG.BlendMode(AGG_BlendSrcTop);

This worked for me but you may need to try several blend modes before getting the right answer.

终止放荡 2024-09-17 01:50:40

尝试 BitmapAlphaTransparency(wholemap, 0);在 WG.attach 之前。

Try BitmapAlphaTransparency(wholemap, 0); before WG.attach.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文