相关疑难解决方法(0)

Android:如何以字节为单位读取文件?

我试图在Android应用程序中获取以字节为单位的文件内容.我现在在SD卡中获取文件想要以字节为单位获取所选文件.我用谷歌搜索,但没有这样的成功.请帮忙

下面是获取扩展名文件的代码.通过这个我得到的文件和旋转显示.在文件选择上我想以字节为单位获取文件.

private List<String> getListOfFiles(String path) {

   File files = new File(path);

   FileFilter filter = new FileFilter() {

      private final List<String> exts = Arrays.asList("jpeg", "jpg", "png", "bmp", "gif","mp3");

      public boolean accept(File pathname) {
         String ext;
         String path = pathname.getPath();
         ext = path.substring(path.lastIndexOf(".") + 1);
         return exts.contains(ext);
      }
   };

   final File [] filesFound = files.listFiles(filter);
   List<String> list = new ArrayList<String>();
   if (filesFound != null && filesFound.length > 0) {
      for (File file : filesFound) {
         list.add(file.getName());
      }
   }
   return list;
}
Run Code Online (Sandbox Code Playgroud)

java android file

57
推荐指数
4
解决办法
8万
查看次数

从 Android 平台发送 Bitmap 到 Flutter

我正在创建一个图像处理应用程序,因此首先使用 android 平台 apis 来处理位图广告,然后将其发送到 flutter。我正在使用下面的代码将位图转换为字节 []

  Bitmap bitmap = BitmapFactory.decodeFile(uri.getPath());
        ByteBuffer allocate = ByteBuffer.allocate(bitmap.getByteCount());
        bitmap.copyPixelsToBuffer(allocate);
        byte[] array = allocate.array();
Run Code Online (Sandbox Code Playgroud)

然后使用 Method Channel 作为 Uint8List 将其发送到 flutter 但当我将其读取为 Image.memory() 时。它给了我错误

解码图像失败。数据无效,或使用不受支持的格式编码。以下是我的主要活动的代码

package com.rahul.flutterappdomain;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;

import com.asksira.bsimagepicker.BSImagePicker;
import com.asksira.bsimagepicker.Utils;

import java.nio.ByteBuffer;

import io.flutter.app.FlutterFragmentActivity;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class ActivityMain extends FlutterFragmentActivity implements BSImagePicker.OnSingleImageSelectedListener{
    private static final String TAG = "DomainFilterFlutterApp";
    private static final String CHANNEL = "com.rummy.io/filter"; …
Run Code Online (Sandbox Code Playgroud)

android dart flutter

10
推荐指数
2
解决办法
6576
查看次数

标签 统计

android ×2

dart ×1

file ×1

flutter ×1

java ×1