gpt4 book ai didi

Android PNG 到位图 --- SkImageDecoder::Factory 返回 null

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:11:06 25 4
gpt4 key购买 nike

我正在尝试从我的 Environment.getExternalStorageDirectory() 加载屏幕截图并尝试将其转换为位图

 public void onPictureTaken(String path) throws IOException {

String photoPath = filepath + "/" + path;; //UPDATE WITH YOUR OWN JPG FILE

File directory = new File (filepath);
File file = new File(directory, path);

final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(photoPath, options);

// Calculate inSampleSize
options.inSampleSize = 4;
options.inJustDecodeBounds = false;
BitmapFactory.decodeFile(photoPath, options);

}

--- SkImageDecoder::Factory returned null

这是调用 onPictureTaken 的函数:

 private void observeSceenshot(){
filepath = Environment.getExternalStorageDirectory()
+ File.separator + Environment.DIRECTORY_PICTURES
+ File.separator + "Screenshots";
Log.d(TAG, filepath);

FileObserver fileObserver = new FileObserver(filepath, FileObserver.CREATE) {
@Override
public void onEvent(int event, String path) {
Log.d(TAG, event + " " + path);
try {
onPictureTaken(path);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
};

fileObserver.startWatching();
}

有人知道如何解决这个问题吗?也许是因为我的 png 太大了(1280x720)?我也试过这个解决方案,结果相同: http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

编辑:这是日志

03-02 11:56:19.806 11581-11716/com.example.chilred_pc.myapplication D/DBG_com.example.chilred_pc.myapplication.ObserveScreenshots: 256 Screenshot_2016-03-02-11-56-19.png 03-02 11:56:19.806 11581-11716/com.example.chilred_pc.myapplication D/directory: /storage/emulated/0/Pictures/Screenshots 03-02 11:56:19.806 11581-11716/com.example.chilred_pc.myapplication D/file: /storage/emulated/0/Pictures/Screenshots/Screenshot_2016-03-01-16-38-08.png 03-02 11:56:19.806 11581-11716/com.example.chilred_pc.myapplication D/fileSize: 35061 03-02 11:56:19.807 11581-11716/com.example.chilred_pc.myapplication D/skia: --- SkImageDecoder::Factory returned null 03-02 11:56:19.808 11581-11716/com.example.chilred_pc.myapplication D/skia: --- decoder->decode returned false

最佳答案

我认为问题的解决方案是屏幕截图需要几秒钟才能创建图像。所以我试着让系统停止几秒钟,现在它开始工作了。

> SystemClock.sleep(3000);

但最后我使用了另一种方法,如下所示: Detect only screenshot with FileObserver Android

关于Android PNG 到位图 --- SkImageDecoder::Factory 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35744376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com