5

I'm trying to load images to an array and can't figure out the syntax. I'm used to something like this in C#:

picture.Image = Image.FromFile(fileLocation);

That doesn't work here. Can anyone help me with this syntax, and any applicable imports I need to make. This is what I have:

public class Beards extends ActionBarActivity
{

Image [] beard = new Image[20];
String [] beardLocation = new String [20];

public void fillArrays()
{
    for (int i = 0; i < 20; i++)
    {
        beardLocation[i] = "C:/Users/geoffoverfield01/AndroidStudioProjects/TheBeadery2.0/Images/Beards/pic_" + i + ".jpg";
    }
    for (int x =0;x<20;x++)
    {
        beard[x] = ImageIO.read(new File(beardLocation[x]));        }

}
...
}

The library that allows me to use the ImageIO won't load.

Uchiha Itachi
  • 1,251
  • 1
  • 16
  • 42
  • I can't load the library to let me use my image files. Anyone know where this might be located in AS??? – Uchiha Itachi May 11 '15 at 20:24
  • From the answer to the question I linked: "ImageIO is not supported in Android SDK" – Alex Wittig May 11 '15 at 20:30
  • 1
    As a side note, if possible I would highly recommend using ArrayList instead of an actual array. They are much easier to resize, saving space on your application. – Evan Bechtol May 11 '15 at 20:30
  • @FiveNine You should reference the answer instead of trying to close as duplicate. The question referenced is not the same as the one being posed here, although there are **similarities** – Evan Bechtol May 11 '15 at 20:31
  • This is a very interesting question, I didn't realize that android didn't support this. – Petro May 11 '15 at 20:33
  • If the ImageIO is not supported in Android SDK, do you know how I might be able to use images in my Android app without making new activities to link to the images?? – Uchiha Itachi May 11 '15 at 21:35

1 Answers1

2

I had to load some images for my Android project. This codes reads images and puts them into an Array.

 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>();
        bitmaps.add(BitmapFactory.decodeResource(this.getResources(), R.raw.one));
        bitmaps.add(BitmapFactory.decodeResource(this.getResources(), R.raw.two));
        bitmaps.add(BitmapFactory.decodeResource(this.getResources(), R.raw.three));
        bitmaps.add(BitmapFactory.decodeResource(this.getResources(), R.raw.four));

Image is sitting on /res/raw/

my images are named one.jpg two.jpg three.jpg four.jpg

Thanks.

MaRin
  • 48
  • 4