Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9244467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:02:24+00:00 2026-06-18T09:02:24+00:00

I am trying to create an array of images that can be drawn on

  • 0

I am trying to create an array of images that can be drawn on a canvas. This is what I have:

List<Integer> imageHolder = new ArrayList<Integer>(); 
imageHolder.add((int)R.drawable.bus_1);
imageHolder.add((int)R.drawable.bus_2);
imageHolder.add((int)R.drawable.bus_3);

Then I try and access the images like this from my onDraw method:

protected void onDraw(Canvas canvas) {
        canvas.drawColor(Color.BLACK);


        for (int i = 0; i < imageHolder.size(); i++){


            canvas.drawBitmap(imageHolder.get(i), 0, 0, null);
        }


    }

But I get an error saying that my arguments are not applicable for my canvas.drawbitmap. Does anyone know how to do this?I have been looking all over for an explanation on how to do this and I can’t find it anywhere.

EDIT: This is how I got it working to print out the 3 images at different points on the screen:

for (int i = 0; i < imageHolder.size(); i++) {
    bMap = BitmapFactory.decodeResource(res, imageHolder.get(0));
    canvas.drawBitmap(bMap, 100, 100, null);
    bMap2 = BitmapFactory.decodeResource(res, imageHolder.get(1));
    canvas.drawBitmap(bMap2, 500, 100, null);
    bMap3 = BitmapFactory.decodeResource(res, imageHolder.get(2));
    canvas.drawBitmap(bMap3, 900, 100, null);
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:02:25+00:00Added an answer on June 18, 2026 at 9:02 am

    What you do is you initially add a bunch of integers to an ArrayList and then you try to loop through this ArrayList and draw a Bitmap, using a resource identified by this integer. The problem is that the first argument to the drawBitmap method in the Canvas class must be either an integer array of colors or a Bitmap resource. Not just an integer, pointing to one. For more information, check the documentation.

    In order to get a specific resource by ID as Bitmap you need to do this:

    Bitmap bMap = BitmapFactory.decodeResource(getResources(), R.drawable.your_drawable_id);
    

    Or in your case your loop needs to look like this:

    Resources res = getResources(); // Cache them
    Bitmap bMap;
    for (int i = 0; i < imageHolder.size(); i++){
        bMap = BitmapFactory.decodeResource(res, imageHolder.get(i));
        canvas.drawBitmap(bMap, 0, 0, null);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create an array or list that could handle in theory,
I'm trying to create an array of strings that can be randomized and limited
I am trying to create and array of objects so that I can access
I'm trying to convert .tiff's to an array, so that I can add images
I am trying to create an array of product SKU's which I can then
I'm trying to create an array from selected table rows so I can push
I am trying to create an array of class objects taking an integer argument.
I'm trying to create an array of structs and also a pointer to that
I am trying to programatically create a bitmap from an array that contains color
Im trying to create a conditional statement that iterates through an array of nodes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.