【问题标题】:load picture from android phone into byte[]从安卓手机加载图片到字节[]
【发布时间】:2013-12-11 16:21:42
【问题描述】:

我想加载我在智能手机中的图片,这样我就可以通过互联网将它发送到我创建的网络服务。

在这里,我提供了我正在尝试但不工作的示例代码。

Bitmap bm = BitmapFactory.decodeFile(path);
System.out.println("BITMAP: "+bm != null);
ByteArrayOutputStream buffer = new ByteArrayOutputStream(bm.getWidth() *bm.getHeight());
bm.compress(CompressFormat.JPEG, 100, buffer);

我确保系统输出时 bm 不为空。我在 ByteArrayOutputStream 中得到 NullPointerException。有什么建议吗?

【问题讨论】:

    标签: java android bitmap buffer bytearray


    【解决方案1】:

    试试这个。使用带有路径的文件名

    String[] files = null;
    File path = new File(Environment.getExternalStorageDirectory(),"folder path");
    if(path.exists())
    {
        filename = path.list();
    }
    for(int i=0; i<count;i++)
    {
         Bitmap bitmapOrg = BitmapFactory.decodeFile(path.getPath()+"/"+ files[i]);
    }
    

    【讨论】:

      猜你喜欢
      • 2011-11-16
      • 1970-01-01
      • 2013-03-09
      • 2012-01-23
      • 2013-01-06
      • 1970-01-01
      • 2016-07-08
      • 1970-01-01
      相关资源
      最近更新 更多