我在做像window画板中的颜色填充工具,我用的是这个算法:
public void Boundary(float x,float y,int boundaryvalue,int newvalue){
  if(GetPixel(x,y)!=boundaryvalue&&GetPixel(x,y)!=newvalue){
  SetPixel(x,y,newvalue);
  Boundary(x, y-1, boundaryvalue, newvalue);
  Boundary(x, y+1, boundaryvalue, newvalue);
  Boundary(x-1, y, boundaryvalue, newvalue);
  Boundary(x+1, y, boundaryvalue, newvalue);
  }
  }
但Canvas中没有GetPixel和SetPixel这两个函数。我想问的是,怎么样才能获得Canvas中的一个点的颜色值。

解决方案 »

  1.   

    看手册的描述
    The Canvas class holds the "draw" calls. To draw something, you need 4 basic components: A Bitmap to hold the pixels, a Canvas to host the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, Path, text, Bitmap), and a paint (to describe the colors and styles for the drawing). Canvas提供的画图的方法本身不存储像素内容,存储像素内容的是和他绑定的Bitmap对象。