Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android importing images to array [duplicate]

Tags:

java

arrays

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.

like image 439
Uchiha Itachi Avatar asked Oct 31 '22 04:10

Uchiha Itachi


1 Answers

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.

like image 66
MaRin Avatar answered Nov 11 '22 11:11

MaRin