- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试从我的 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/
我正在尝试使用以下代码行将图像加载到我的 ImageView 中: iv_flagged.setImageResource(R.drawable.not_flagged); 但是,当我运行这行代码时,
我正在尝试显示来自网络的图像..我正在使用 RemoteImageView 的点火库..这是代码.. public class images extends Activity{ public Stri
我在 Android 上编程并通过此调用从远程 URL 读取图像 BitmapFactory.decodeStream( ... 随机的,我得到错误: SkImageDecoder::Factory
我正在尝试将图像从 URL 加载到 ImageView 但出现错误:SkImageDecoder::Factory 返回空值。我该如何解决? 这是我的代码: private class LoadIma
我正在使用我的本地主机来获取图像并在 ImageView 中查看。出于某种原因,我收到了 Factory 返回的 null 错误。我已经多次查看代码,但我看不出有什么问题。任何帮助将不胜感激! Gal
我正在尝试将屏幕截图从桌面发送到 Android,并在 Android 上显示。据我所知,返回 null 可能是因为我没有 inputStream.read() 读取所有输入流,因此我做了一个 whi
我将我的 View imageview 传递到我创建的这个 imageloader 类中,但由于某种原因我收到此错误“SkImageDecoder::Factory returned null”,这似
这是一种解码图像的方法。调用时,它会抛出 SkImageDecoder::Factory 并返回 null。 private static Bitmap decodeFile(File f) {
我正在尝试从远程服务器下载图片,下载的图片数量是 30。我用来下载图片的代码如下。一些图片下载成功,一些图片没有下载并引发上述异常。可能是什么问题。 public static Bitmap load
这个问题在这里已经有了答案: 关闭10 年前。 代码: URL url = new URL(bitmapurl); HttpURLConnection connection = (HttpURLCo
我正在尝试从我的 Environment.getExternalStorageDirectory() 加载屏幕截图并尝试将其转换为位图 public void onPictureTaken(Stri
目标是将 Bitmap 转换为 byte [],在 Bundle 数据的 Activity 之间传递它,然后重新转换它在稍后阶段返回到 Bitmap 以在 Imageview 中显示。 问题是每当我尝
我使用以下代码从 Internet 下载图像并将其显示在 Android ImageView 中。 private class DownloadImage extends AsyncTask {
我有一个 Spring MVC Web 服务,它以字节数组的形式返回图像。输出为 json 格式。格式为png这是图像的代码 fragment 。 BufferedImage img = ImageI
我试图将来自 URL 的图像放入 ImageView 中,但我不断收到“SkImageDecoder::Factory returned null”错误。 这是我的代码: private class
我有一个 TouchPoint 类,它实现了 Serializable,因为它包含 Bitmap,所以我为该类编写了 writeObject 和 readObject: private void wr
我是一名优秀的程序员,十分优秀!