【问题标题】:Android importing images to array [duplicate]Android将图像导入数组[重复]
【发布时间】:2015-05-12 07:23:44
【问题描述】:

我正在尝试将图像加载到数组中,但无法弄清楚语法。我在 C# 中已经习惯了这样的事情:

picture.Image = Image.FromFile(fileLocation);

这在这里行不通。任何人都可以帮助我使用这种语法以及我需要进行的任何适用的导入。这就是我所拥有的:

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]));        }

}
...
}

不会加载允许我使用 ImageIO 的库。

【问题讨论】:

  • 我无法加载库来让我使用我的图像文件。有人知道这可能位于 AS 的什么地方吗???
  • 从我链接的问题的答案:“Android SDK 不支持 ImageIO”
  • 附带说明,如果可能的话,我强烈建议使用 ArrayList 而不是实际的数组。它们更容易调整大小,节省应用程序的空间。
  • @FiveNine 您应该参考答案,而不是尝试关闭为重复项。所引用的问题与此处提出的问题不同,尽管存在相似之处
  • 这是一个很有意思的问题,没想到android不支持这个。

标签: java arrays


【解决方案1】:

我必须为我的 Android 项目加载一些图像。此代码读取图像并将它们放入数组中。

 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));

图像位于 /res/raw/

我的图片被命名为 one.jpg two.jpg three.jpgfour.jpg

谢谢。

【讨论】:

    猜你喜欢
    • 2018-04-27
    • 2023-03-14
    • 1970-01-01
    • 2016-10-09
    • 1970-01-01
    • 2020-09-26
    • 2012-03-09
    • 1970-01-01
    • 2022-11-11
    相关资源
    最近更新 更多