我使用滑行提取從緩存中的位圖,並將其保存在其他地方。下面的相關函數(根據此post :)無法觸發提取。實際上,日誌行'Log.d(TAG,「即將開始提取」);''下面永遠不會被觸發。滑翔圖像截取
爲什麼簡單的目標函數不會被調用任何想法?
public byte[] extractImageFromCache(Context context, String pictureURL) {
byte[] byteArray = new byte[0];
if (context != null && pictureURL != null && !pictureURL.isEmpty()) {
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Glide.with(context)
.load(pictureURL)
.asBitmap()
.toBytes()
.diskCacheStrategy(DiskCacheStrategy.SOURCE) // Load the original hires image
.into(new SimpleTarget<byte[]>() {
@Override public void onResourceReady(final byte[] resource, GlideAnimation<? super byte[]> glideAnimation) {
Log.d(TAG, "About to start extraction");
new AsyncTask<Void, Void, Void>() {
@Override protected Void doInBackground(Void... params) {
Log.d(TAG, "Start extraction");
try {
Log.d(TAG, "Image bytes len: " + resource.length);
byteArrayOutputStream.write(resource);
byteArrayOutputStream.flush();
} catch (IOException e) {
e.printStackTrace();
Log.i(TAG, "Unable to load image: " + pictureURL);
e.printStackTrace();
}
return null;
}
}.execute();
}
});
Log.d(TAG, String.format("Got image bytes: %d for %s", byteArrayOutputStream.size(), pictureURL));
return byteArrayOutputStream.toByteArray();
}
return null;
}
你能後的logcat的? – azizbekian
你在哪裏調用這個函數? – rom4ek
提及Glide版本,我試過了你的代碼,它在'glide:3.7.0' – Maddy