我試圖從給定的位圖中提取輪廓路徑,我在AS3創建一個快速算法(對我來說),那就是:關於:提取區域從位圖
//@v source bitmap's vector data
//@x x to starting extraction
//@y y to stating extraction
//@w extraction width
//@h extraction height
//@mw source bitmap width
//@mh source bitmap height
private function extractRects(v:Vector.<uint>, x:int, y:int,
w:int, h:int, mw:int, mh:int):Array
{
var ary:Array = [], yy:int=y, vStart:int, _xx:int, xx:int;
var lcold:int = 0, lc:int;
//first line to last line
while(yy < h)
{
//first index of current vector
vStart = yy * mw + x;
xx = x;
lc = 0;
//first vector to last on current scan
while(xx < w)
{
/*
if current vector value (color) is
empty (transparent) then
check next
*/
while(xx < w && !v[vStart])
{
vStart++;
xx++;
}
//it is not empty so copy first index
_xx = xx;
//check till value is not empty
while(xx < w && v[vStart])
{
xx++;
vStart++;
}
//create rectangle
var rr:Rectangle = new Rectangle(_xx, yy, (xx-_xx), 1);
//if previous line has the same rectangle index
if(lc < lcold)
{
var oldrr:Rectangle = ary[ary.length - lcold];
//if previous neighbour rect on top
//has same horizontal position then
//resize its height
if(oldrr.left == rr.left && oldrr.width == rr.width)
oldrr.height++;
else
ary.push(rr);
}
else
ary.push(rr);
lc++;
xx++;
}
lcold = lc;
yy++;
}
return ary;
}
通過以上方法,我解壓地區和通過繪製rects創建形狀。 由於不光滑的視圖,繪製rects對我來說不是一個好的解決方案。
有更平滑的視圖,我應該使用線條或曲線,但計算鄰點對我來說真的是頭痛目眩。
你能推薦我一些知名或更好的解決方案嗎?如果你的答案是錯誤的,那麼你可以使用as3,C++,c#,vb.net,vb6,delphi,java或類似的語言。
感謝您提前..
編輯CLEARIFICATION
我試圖提取非透明像素X,Y從位圖座標上的不同路徑的數據繪製。 (32位ARGB)(創建形狀)
繪製我可以使用了lineTo,curveTo,moveTO操作
moveTo(x, y)
lineTo(x, y)
curveTo(cx, cy, ax, ay)
在我的代碼,我認爲我可以提取當前非透明塊的矩形和我可以使用與的moveTo和了lineTo操作相同rects上進一步圖解法
是使用此方法給出了邊緣不光滑的外觀的問題,就是neighter水平也不垂直
所以,解決方案是創建一個點米使用lineTo操作(因爲它會生成反鋸齒線),或者計算最近的圓區域上的點放置以及使用curveTo方法..
我的問題是你可以嗎?向我推薦一些提取作業的算法或方法。
對不起我的英語
謝謝
我不明白這個問題。你是從一個位圖複製一個矩形區域?你說'我抽出區域並通過繪製矩形來創造形狀',這是什麼意思?如果你用一個具體的例子來描述算法應該做什麼,也許會更容易理解。 – Roel 2009-06-05 08:44:46