Thanks Mike, what I ended up with yesterday looks a lot like your code
(sourceImage is a Drawable object, the grid of images):

                int w=32, h=32; // target size of images
                int width = sourceImage.getIntrinsicWidth();
                int height = sourceImage.getIntrinsicHeight();
                int top = 0, left = 0, maxImages = 0;

                Bitmap sourceBitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
                Canvas sourceCanvas = new Canvas(sourceBitmap);
                sourceImage.setBounds(0, 0, width, height);
                sourceImage.draw(sourceCanvas);

                //sourceBitmap now contains grid of sprite images
                while ( top < height ) {
                        while ( left < width ) {
                                image[maxImages] = Bitmap.createBitmap(w, h,
Bitmap.Config.ARGB_8888);
                                Canvas canvas = new Canvas(image[maxImages]);
                                canvas.drawBitmap(sourceBitmap, -left, -top, 
mPaint);
                                left += w;
                                maxImages++;
                        }
                        left = 0;
                        top += h;
                }
                currentImage = 0;


On 28 Oct, 15:43, Mike Reed <[EMAIL PROTECTED]> wrote:
> The way to "copy" a drawable into a bitmap is to draw it there.
>
> void draw(Drawable dr, Bitmap bm, int left, int top) {
>      Canvas c = new Canvas(bm);
>      c.translate(-left, -top);
>      dr.draw(canvas);
>
> }
>
> void loop() {
>      Drawable dr = // your master drawable
>      dr.setBounds(0, 0, 320, 320);
>      for (int y = 0; y < 10; y++) {
>          for (int x = 0; x < 10; x++) {
>              Bitmap bm = // the bitmap at cell location (x, y)
>              draw(dr, bm, x * 32, y * 32);
>          }
>      }
>
> }
>
> mike
>
> On Oct 27, 2008, at 11:57 AM, PorkChop wrote:
>
> OK thanks Ludwig.
>
> On 27 Oct, 11:25, Ludwig <[EMAIL PROTECTED]> wrote:
>
> > I am not entirely sure if this is what you are looking for, but the  
> > Canvas
> > has a method where you can specify the a source and destination  
> > rectangle to
> > draw from and to:
> > public void 
> > drawBitmap(Bitmap<file:///C:/Software/android/docs/reference/android/graphics/Bitmap.html
>
> >  bitmap, 
> > Rect<file:///C:/Software/android/docs/reference/android/graphics/Rect.html
>
> >  src, 
> > Rect<file:///C:/Software/android/docs/reference/android/graphics/Rect.html
>
> >  dst, 
> > Paint<file:///C:/Software/android/docs/reference/android/graphics/Paint.html
>
> >  paint)
>
> > HTH
>
> > Ludwig
>
> > 2008/10/26 PorkChop <[EMAIL PROTECTED]>
>
> >> What I am trying to achieve is breaking a drawable down into an array
> >> of separate bitmaps. E.g. I am passing a grid of 32x32 images (lets
> >> say the image is 320x320 pixels and contains a grid of 10x10 smaller
> >> bimap images) and i want to create an array of 100 bitmaps.
>
> >> So I need to copy from (eg) x=32, y=32, w=32,h=32 into another bitmap
> >> which is 32x32 pixels. Anyone got any idea how to do this? Hope I  
> >> have
> >> explained this well enough.
--~--~---------~--~----~------------~-------~--~----~
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