2010-07-18 67 views
2

什麼我嘗試做AggPas德爾福繪圖膠片

我有一個繪圖程序(它的工作原理),它繪製成位圖「OBJmap」它進而提出OBJmap到Wholemap。這一切都有效,但有一個問題。它似乎將objmap的未定義部分視爲白色,即使objmap和wholemap設置爲PF32Bit,因此,當它將objmap放入整個映射中時,我會在粘貼的圖像後面顯示一個應該透明的白框。

這隻發生在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; 

形象的例子

不工作,工作和當前respectivly

alt text alt text alt text

我只能夠得到工作結果上Nvidia的機器用默認

wholemap.Canvas.Draw 

方法,我希望得到它的使用aggpass所有機器正常工作。

我該怎麼做我如何在全圖上繪製objmap,但不繪製透明位?

+0

仍然卡在這裏:( – Arthur 2010-07-21 11:17:35

回答

2

我有同樣的問題,你需要在調用變換的圖像

WG.BlendMode(AGG_BlendSrcTop); 

這爲我工作之前設置的BlendMode但您可能需要獲得正確的答案之前,嘗試幾種混合模式。

2

嘗試BitmapAlphaTransparency(wholemap,0);在WG.attach之前。

+0

如果我現在使用TransformImage設置bitmapalpha它獲得圖像的輪廓,背景是alpha255和對象是alpha0 ,,,有沒有辦法只是簡單地翻轉alpha通道?,,,它現在看起來像這樣, http://i44.photobucket.com/albums/f14/keahicheveyo/outside.jpg – Arthur 2010-07-19 09:42:39

+2

AggPas不提供在另一個TBitmap上繪製一個TBitmap的功能,它可以只需附加到TBitmap並在那裏渲染內容,或者直接粘貼到整個地圖並在那裏渲染,或者使用像Gr32這樣的位圖導向庫來處理混合一個TBitmap到另一個TBitmap。如果你想翻轉Alpha,看看BitmapAlphaTransparency函數並基於Alpha翻轉功能創建一個新的,幾乎微不足道的。 – Milan 2010-07-19 13:25:03

+1

非常感謝爲評論! AggPas很棒! – SOUser 2011-03-06 10:11:53