I think you misunderstand me. They are in different functions. One is
on onCreate and the other is in onDraw. They are differenct canvas.
On Apr 8, 1:49 pm, Rui Martins <[EMAIL PROTECTED]> wrote:
> You are doing something really strange!
>
> First you setup a bitmao as your canvas
> bitmap = Bitmap.createBitmap(100, 100, true);
> Canvas canvas = new Canvas(bitmap);
>
> But later, you use your canvas ( which uses your bitmap as it's
> buffer) and you draw on it, using itself, i.e. you feedback the same
> bitmap
> canvas.drawBitmap(bitmap, 10, 10, null);
>
> This is shure to fail, since the copy behaviour is not defined how it
> should behave in case you are copying it to itself.
>
> Use different bitmaps, one for canvas, and another for whatever you
> are drawing.
>
> TIP: if you set thePixels(...) of your bitmap (buffer) you don't need
> to draw those same pixels after, since they are already there !
>
> On 8 abr, 04:20, Gibson <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > hi all,
>
> > I wrote following code.
>
> > class MyView extends View {
> > Bitmap bitmap;
>
> > public MyView(Context context) {
> > super(context);
> > Drawable drawable =
> > context.getResources().getDrawable(R.drawable.icon);
> > bitmap = Bitmap.createBitmap(100, 100, true);
> > Canvas canvas = new Canvas(bitmap);
> > drawable.setBounds(0, 0, 100, 100);
> > drawable.draw(canvas);
> > }
>
> > @Override
> > protected void onDraw(Canvas canvas) {
> > Paint paint = new Paint();
> > paint.setARGB(255, 255, 255, 255);
> > canvas.drawRect(0, 0, screenWidth, screenHeight, paint);
> > canvas.drawBitmap(bitmap, 10, 10, null);
> > int[] imagedata = new int[100 * 100];
> > bitmap.getPixels(imagedata, 0, 100, 0, 0, 100, 100);
> > bitmap.setPixels(imagedata, 0, 100, 0, 0, 100, 100);
> > invalidate();
>
> > try {
> > Thread.sleep(100);
> > } catch (InterruptedException e) {
> > }
> > }
>
> > int screenWidth, screenHeight;
>
> > @Override
> > protected void onSizeChanged(int i, int j, int k, int l) {
> > screenWidth = i;
> > screenHeight = j;
> > super.onSizeChanged(i, j, k, l);
> > }
>
> > }
>
> > These code just retrieve the pixel data and then put them back. But
> > why i got different result on the screen. It seems like the retrieve
> > method change some pixel? Can anybody help me with this please?
> > Thanks.
>
> > BR
> > Gibson
--~--~---------~--~----~------------~-------~--~----~
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]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---