Renderscript Carousel Example

Go To StackoverFlow.com

0

I don't have much experience with Renderscript, but I'm wanting to learn a little more. I found this example from Google, but I'm unsure how to actually load my own images into the carousel.

I'm confused about loading more than one image into the carousel, because it doesn't use an Adapter, but rather one Bitmap and I'm unsure how to go about changing this.

 BitmapFactory.decodeResource(res,R.drawable.glossy_overlay);

I've done some research, but it's difficult to find solid examples for someone without much experience. Would someone provide some resources or an example of how I could load my own images into the carousel?

2012-04-04 08:16
by adneal


0

Define static List in CarouselTestActivity

private static final int[] DEFAULT_RESOURCE_LIST =
{ R.drawable.image01, R.drawable.image02, R.drawable.image03,R.drawable.image04, R.drawable.image05,R.drawable.image01, R.drawable.image02, R.drawable.image03,R.drawable.image04, R.drawable.image05}; }

Modify value

    private static final int TOTAL_CARDS =DEFAULT_RESOURCE_LIST.length ;

Modify getTexture in LocalCarouselViewHelper in the same class

@Override public Bitmap getTexture(int n) {

        final Bitmap bitmap = ((BitmapDrawable) getResources()
                .getDrawable(DEFAULT_RESOURCE_LIST[n])).getBitmap();
        return bitmap;
        /*
        Bitmap bitmap = Bitmap.createBitmap(TEXTURE_WIDTH, TEXTURE_HEIGHT,
                Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        canvas.drawARGB(0, 0, 0, 0);
        mPaint.setColor(0x40808080);
        canvas.drawRect(2, 2, TEXTURE_WIDTH-2, TEXTURE_HEIGHT-2, mPaint);
        mPaint.setTextSize(100.0f);
        mPaint.setAntiAlias(true);
        mPaint.setColor(0xffffffff);
        canvas.drawText("" + n, 2, TEXTURE_HEIGHT-10, mPaint);
        canvas.drawBitmap(mGlossyOverlay, null,
                new Rect(PIXEL_BORDER, PIXEL_BORDER,
                        TEXTURE_WIDTH - PIXEL_BORDER, TEXTURE_HEIGHT - PIXEL_BORDER), mPaint);
        return bitmap;
        */
    }

Enjoy...

2012-08-31 09:37
by Stephane
Ads