Hi,

Another approach would be to cache the visible area and only update/
replace the area you want to change from within a different method.
Some example code stubs.
Call the drawMe method whenever you want to replace the Image at the
given location.
You can also provide a Rect to position the Bitmap within the buffer
and call incalidte(dirtyRect) to improve performance.

Please let me know how it worked out for you.

  Bitmap mBuffer;
  Canvas mCanvas;

  public TestView(Context context, AttributeSet attrs)
  {
    super(context, attrs);

  }

  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh)
  {
    super.onSizeChanged(w, h, oldw, oldh);
    mBuffer = Bitmap.createBitmap(w,h,Config.ARGB_8888);
    mCanvas = new Canvas(mBuffer);
  }

  @Override
  protected void onDraw(Canvas canvas)
  {
    super.onDraw(canvas);
    if (mBuffer!=null)
      canvas.drawBitmap(mBuffer, 0,0,null);
  }

  public void drawMe(int dx, int dy, Bitmap bm)
  {
    if (mCanvas!=null)
      mCanvas.drawBitmap(bm,dx,dy,null);
    invalidate();
  }





On 4 Mrz., 10:16, jamesc <[email protected]> wrote:
> Looking at your code, you're drawing the bitmap at the top-left of the
> canvas (i.e. canvas.drawBitmap(bitmap, 0, 0 ...).  Presumably, you're
> precalculating where the bitmap needs to be drawn (it's top-left
> coordinate) and using those values in the drawBitmap() call?
>
> The onDraw method will only draw what you tell it to.  So, what I
> presume is happening is that you're asking it to first render this:
>
> 1 0 0
> 0 0 0
> 0 0 0
>
> which it does, then you ask it to render the bitmap at (I'm assuming
> that each '1' is a single bitmap):
>
> 0 0 0
> 0 1 0
> 0 0 0
>
> The problem is, is that you've not told it about the first bitmap (at
> the top-left corner), so it doesn't bother drawing that and just
> renders the bitmap in the middle.
>
> Thus, to fix this, you need to be able to keep a track of all the
> bitmaps that you want to draw, and where they're to be drawn.
>
> On Mar 4, 8:09 am, CMF <[email protected]> wrote:
>
> > Let consider this is my tile view (which is a bitmap):
>
> > 0 0 0
> > 0 0 0
> > 0 0 0
>
> > First, I have change the view to
>
> > 1 0 0
> > 0 0 0
> > 0 0 0
>
> > Second, I would like to change the middle one, and I expect the result
> > is
> > 1 0 0
> > 0 1 0
> > 0 0 0
>
> > However, the view give the result:
> > 0 0 0
> > 0 1 0
> > 0 0 0
>
> > Is there any method that I can draw the particular part but now the
> > whole view?
> > Here is my onDraw()
>
> > @Override
> >         protected void onDraw(Canvas canvas)
> >         {
> >                 super.onDraw(canvas);
> >                 Bitmap bitmap = getImage(R.drawable.tileboard);
> >                 bitmap.setDensity(canvas.getDensity());
> >                 canvas.drawBitmap(bitmap, 0, 0, new 
> > Paint());//drawtilebackground
> >         }

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to