【问题标题】:Is it possible to create an android.media.image instance from a file?是否可以从文件创建 android.media.image 实例?
【发布时间】:2017-11-13 09:15:37
【问题描述】:

我想创建一个android.media.Image 实例,其中包含一个从存储加载的文件。 因为我想做这样的事情:

 final Plane[] planes = image.getPlanes();
 final int yRowStride = planes[0].getRowStride();
 final int uvRowStride = planes[1].getRowStride();
 final int uvPixelStride = planes[1].getPixelStride();

有什么想法吗?

【问题讨论】:

  • 存储中的图片有哪些格式?
  • @DamiaFuentes jpg 是格式

标签: android tensorflow


【解决方案1】:

试试这个代码:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(photoPath, options);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.Compress (Bitmap.CompressFormat.Jpeg, 100, stream);
ImageReader reader = ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 5);
Image img = reader.acquireLatestImage();
if(img != null){
    final Plane[] planes = image.getPlanes();
    final int yRowStride = planes[0].getRowStride();
    final int uvRowStride = planes[1].getRowStride();
    final int uvPixelStride = planes[1].getPixelStride();
}

当然,你需要处理(丢失文件或错误的名称/路径、选项和压缩格式)

【讨论】:

  • 你从哪里得到这个类“MemoryStream”? Android Studio 告诉我他无法解析符号“MemoryStream”
  • 如果以后不使用,将bitmap保存到stream有什么意义? .... 根本没有... 那么在这段代码中加载bitmap 有什么意义呢?没有 ... 因为我们不需要将其放入 stream 并且我们没有将 bitmap 对象用于将其放入此流的其他事物... 回顾:阅读器代码不是与加载代码相关,所以这是无用的
  • @Selvin 问题是我无法测试这段代码:想法是最终将位图保存到文件中,以便他可以从 'aqcuireLatestImage()' 获取它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-18
  • 2011-11-05
  • 2015-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多