1
AndroidのOpenCVアプリケーションを作成していて、機能をテストするために、自分のコンピュータからサンプル画像を読み込んで結果をコンピュータに保存して、正しく動作します。 Androidスタジオのresourcesフォルダの下にjpgファイルを置いて、このフォルダからファイルを読み込めますが、BitmapFactoryは常にnullを返します。この問題をどのように解決すればよいですか?Androidスタジオで単体テスト用の画像を読み込む
File file = getFileFromPath(this, "roi_RGB.jpg");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inSampleSize = 4;
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), options);
ように私は、画像を読み込む:ビットマップは常にnullである
private static File getFileFromPath(Object obj, String fileName) {
ClassLoader classLoader = obj.getClass().getClassLoader();
URL resource = classLoader.getResource(fileName);
return new File(resource.getPath());
}
。
私は自分のイメージをリソースフォルダに入れて読み込みました。 (私の記事で編集)。私はまだヌルビットマップを取得 – hAlE