0
A
回答
0
你將不得不玩的位圖,顏色轉換矩陣和Alpha通道。
這樣的(不具有代碼手頭copypaste): 1.創建從經由彩色矩陣的黑色像素的alpha通道位圖(黑 - >的α1) 2.桶填充綠色矩形超過alpha通道 3。桶填充藍色矩形超過alpha通道 4.拉伸比原始位圖
3
是的,這可以通過使用下面的代碼:
圖片用於填充:http://i.stack.imgur.com/7rita.jpg
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/relative_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_weight="1" >
<ImageView
android:id="@+id/coringImage"
android:layout_width="300dp"
android:layout_height="300dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/btn_red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="red" />
<Button
android:id="@+id/btn_yellow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="yellow" />
<Button
android:id="@+id/btn_blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="blue" />
</LinearLayout>
</LinearLayout>
活動課
public class FillColorActivity extends Activity implements OnTouchListener {
private RelativeLayout drawingLayout;
private MyView myView;
Button red, blue, yellow;
Paint paint;
/** Called when the activity is first created. */
/*
*
* private ImageView imageView; private Canvas cv; private Bitmap mask,
* original, colored; private int r,g,b; private int sG, sR, sB;
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myView = new MyView(this);
drawingLayout = (RelativeLayout) findViewById(R.id.relative_layout);
drawingLayout.addView(myView);
red = (Button) findViewById(R.id.btn_red);
blue = (Button) findViewById(R.id.btn_blue);
yellow = (Button) findViewById(R.id.btn_yellow);
red.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
paint.setColor(Color.RED);
}
});
yellow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
paint.setColor(Color.YELLOW);
}
});
blue.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
paint.setColor(Color.BLUE);
}
});
}
public class MyView extends View {
private Path path;
Bitmap mBitmap;
ProgressDialog pd;
final Point p1 = new Point();
Canvas canvas;
// Bitmap mutableBitmap ;
public MyView(Context context) {
super(context);
paint = new Paint();
paint.setAntiAlias(true);
pd = new ProgressDialog(context);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeWidth(5f);
mBitmap = BitmapFactory.decodeResource(getResources(),
R.drawable.cartoon).copy(Bitmap.Config.ARGB_8888, true);
this.path = new Path();
}
@Override
protected void onDraw(Canvas canvas) {
this.canvas = canvas;
paint.setColor(Color.GREEN);
canvas.drawBitmap(mBitmap, 0, 0, paint);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
p1.x = (int) x;
p1.y = (int) y;
final int sourceColor = mBitmap.getPixel((int) x, (int) y);
final int targetColor = paint.getColor();
new TheTask(mBitmap, p1, sourceColor, targetColor).execute();
invalidate();
}
return true;
}
public void clear() {
path.reset();
invalidate();
}
public int getCurrentPaintColor() {
return paint.getColor();
}
class TheTask extends AsyncTask<Void, Integer, Void> {
Bitmap bmp;
Point pt;
int replacementColor, targetColor;
public TheTask(Bitmap bm, Point p, int sc, int tc) {
this.bmp = bm;
this.pt = p;
this.replacementColor = tc;
this.targetColor = sc;
pd.setMessage("Filling....");
pd.show();
}
@Override
protected void onPreExecute() {
pd.show();
}
@Override
protected void onProgressUpdate(Integer... values) {
}
@Override
protected Void doInBackground(Void... params) {
FloodFill f = new FloodFill();
f.floodFill(bmp, pt, targetColor, replacementColor);
return null;
}
@Override
protected void onPostExecute(Void result) {
pd.dismiss();
invalidate();
}
}
}
// flood fill
public class FloodFill {
public void floodFill(Bitmap image, Point node, int targetColor,
int replacementColor) {
int width = image.getWidth();
int height = image.getHeight();
int target = targetColor;
int replacement = replacementColor;
if (target != replacement) {
Queue<Point> queue = new LinkedList<Point>();
do {
int x = node.x;
int y = node.y;
while (x > 0 && image.getPixel(x - 1, y) == target) {
x--;
}
boolean spanUp = false;
boolean spanDown = false;
while (x < width && image.getPixel(x, y) == target) {
image.setPixel(x, y, replacement);
if (!spanUp && y > 0
&& image.getPixel(x, y - 1) == target) {
queue.add(new Point(x, y - 1));
spanUp = true;
} else if (spanUp && y > 0
&& image.getPixel(x, y - 1) != target) {
spanUp = false;
}
if (!spanDown && y < height - 1
&& image.getPixel(x, y + 1) == target) {
queue.add(new Point(x, y + 1));
spanDown = true;
} else if (spanDown && y < height - 1
&& image.getPixel(x, y + 1) != target) {
spanDown = false;
}
x++;
}
} while ((node = queue.poll()) != null);
}
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return false;
}
}
+0
謝謝它適用於我,但你能否請我提供示例代碼填充圖像用刷子? – 2014-07-07 03:31:56
相關問題
- 1. 如何填充顏色完全像這個圖像的顏色?
- 2. 控制svg圖像填充顏色
- 3. 圖像的填充(顏色)部分
- 4. 掩蓋圖像並填充顏色
- 5. MPAndroidChart餅圖填充顏色
- 6. android:在Canvas中創建圖像並填充顏色
- 7. 用seekbar填充框的顏色(Android)
- 8. Android - 用部分顏色填充路徑
- 9. 用Android的顏色填充ArrayList
- 10. 用python填充顏色密度圖
- 11. ggplot:用顏色填充方塊圖
- 12. UIView填充顏色
- 13. Mathematica填充顏色
- 14. 繪製圖像並用顏色或圖案動態填充
- 15. 如何在填充圖中獲得深色填充顏色?
- 16. 用顏色填充標籤
- 17. 填充顏色的形狀像Paper.io
- 18. 評級酒吧填充顏色的Android
- 19. Android佈局中的填充顏色
- 20. 更改像素以填充WPF圖像中的顏色
- 21. 用顏色填充圖像的一部分
- 22. SVG:將填充顏色應用於懸停的「蒙版」圖像
- 23. 如何用3種隨機顏色的漸變填充圖像?
- 24. 如何插入使用fabricjs在圖像中填充顏色
- 25. PHP:用顏色填充圖像塊並保存信息
- 26. 使用圖像填充畫布區域而不是顏色
- 27. 調整圖像大小並用顏色填充比例間隙
- 28. 將填充(顏色)應用於SVG圖像
- 29. 用圖像填充對象,不用顏色(將圖像繪製到畫布上)
- 30. Android AChartengine:使用不同顏色的填充圖
是的,但我不能接受只有正確回答我的問題... – 2011-06-16 12:52:09
那很好,我只是想告訴你如果你不知道:)更多的,我無法看到圖像的例子.. – Stuti 2011-06-16 12:53:33
我已經上傳和最終的圖像... – 2011-06-16 13:01:31