0
これは私のコードの簡略化されたバージョンです。 appスクリーンの2つのスクリーンショットを取得し、first.pngとsec.pngのstoreはapp \ srcフォルダにあります。私は画像を開いて、それらが正しいスクリーンショットであることを見ることができます。しかし、私がbitmapfactoryを使用してそれらをビットマップに取得しようとすると、nullが返されます。私は絶対パスと相対パスを与えようとしました。私は他の同じ質問応答に従っていますので、重複としてマークする前に見てください。あなたはBitmapFactory.decodeFile
にNPE
を取得している場合はBitmapFactoryのdecodeFileがnullを返します
class Test{
private static boolean compareImages() throws FileNotFoundException {
Bitmap bitmap1 = BitmapFactory.decodeFile("src/"+imgFirst);
Bitmap bitmap2 = BitmapFactory.decodeFile("src/"+imgSecond);
if (bitmap1.getWidth() != bitmap2.getWidth() ||
bitmap1.getHeight() != bitmap2.getHeight()) {
return false;
}
for (int y = 0; y < bitmap1.getHeight(); y++) {
for (int x = 0; x < bitmap1.getWidth(); x++) {
if (bitmap1.getPixel(x, y) != bitmap2.getPixel(x, y)) {
return false;
}
}
}
return true;
}
public static boolean test() {
File scrFile = (Setup.getDriver()).getScreenshotAs(OutputType.FILE);//The Setup.getDriver() returns an AppiumDriver.
FileUtils.copyFile(scrFile, new File(imgFirst));
scrFile = (Setup.getDriver()).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(imgSecond));
if(compareImages())
return false;
else
return true;
}
private static String imgFirst = "first.png";
private static String imgSecond = "sec.png";
}
' BitmapFactory'をインポートしましたか? – nullpointer
'android.graphics.Bitmap'と ' android.graphics.BitmapFactory' – Gsquare
大丈夫です。例外のスタックトレースを追加できますか? – nullpointer