uCrop
uCrop copied to clipboard
It take long time on first time load image
Hi all, I have tried on 2.2.4 or 2.2.4-native but it always happens on the first-time load image. It has loading - more than a minute, blank screen, can not scale or rotate. Thanks for any helping
Hi @nthieu90, can you provide please more details(size of the photo, device-specific, etc.) about this issue.
Hi @Marina24, It happens on many different devices and photos, eg: 960x1028 on Xiaomi Mi A2. If I run for the first time it always takes a long time but on the second it loads immediately.
I have the same issue
I found the solution. In my case,BitmapLoadTask is not executed immediately.So I guess it may be that the thread pool in AsyncTask is full. This is the code of my solution:
public class BitmapLoadUtils {
private static final String TAG = "BitmapLoadUtils";
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
public static final Executor UCROP_THREAD_POOL_EXECUTOR;
private static final int CORE_POOL_SIZE = Math.max(2, Math.min(CPU_COUNT - 1, 4));
private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
private static final int KEEP_ALIVE_SECONDS = 30;
private static final BlockingQueue<Runnable> sPoolWorkQueue =
new LinkedBlockingQueue<Runnable>(128);
private static final ThreadFactory sThreadFactory = new ThreadFactory() {
private final AtomicInteger mCount = new AtomicInteger(1);
public Thread newThread(Runnable r) {
return new Thread(r, "uCropAsyncTask #" + mCount.getAndIncrement());
}
};
static {
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_SECONDS, TimeUnit.SECONDS,
sPoolWorkQueue, sThreadFactory);
threadPoolExecutor.allowCoreThreadTimeOut(true);
UCROP_THREAD_POOL_EXECUTOR = threadPoolExecutor;
}
public static void decodeBitmapInBackground(@NonNull Context context,
@NonNull Uri uri, @Nullable Uri outputUri,
int requiredWidth, int requiredHeight,
BitmapLoadCallback loadCallback) {
new BitmapLoadTask(context, uri, outputUri, requiredWidth, requiredHeight, loadCallback)
.executeOnExecutor(UCROP_THREAD_POOL_EXECUTOR); //Use custom thread pool
}
.....
}
I found the solution. In my case,BitmapLoadTask is not executed immediately.So I guess it may be that the thread pool in AsyncTask is full. This is the code of my solution:
public class BitmapLoadUtils { private static final String TAG = "BitmapLoadUtils"; private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors(); public static final Executor UCROP_THREAD_POOL_EXECUTOR; private static final int CORE_POOL_SIZE = Math.max(2, Math.min(CPU_COUNT - 1, 4)); private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1; private static final int KEEP_ALIVE_SECONDS = 30; private static final BlockingQueue<Runnable> sPoolWorkQueue = new LinkedBlockingQueue<Runnable>(128); private static final ThreadFactory sThreadFactory = new ThreadFactory() { private final AtomicInteger mCount = new AtomicInteger(1); public Thread newThread(Runnable r) { return new Thread(r, "uCropAsyncTask #" + mCount.getAndIncrement()); } }; static { ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor( CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_SECONDS, TimeUnit.SECONDS, sPoolWorkQueue, sThreadFactory); threadPoolExecutor.allowCoreThreadTimeOut(true); UCROP_THREAD_POOL_EXECUTOR = threadPoolExecutor; } public static void decodeBitmapInBackground(@NonNull Context context, @NonNull Uri uri, @Nullable Uri outputUri, int requiredWidth, int requiredHeight, BitmapLoadCallback loadCallback) { new BitmapLoadTask(context, uri, outputUri, requiredWidth, requiredHeight, loadCallback) .executeOnExecutor(UCROP_THREAD_POOL_EXECUTOR); //Use custom thread pool } ..... }
Did it work?