我正在开发一个Android应用程序,向用户显示全屏图像.从服务器获取图像.我正在使用Glide来显示图像.但是我希望在显示实际图像之前显示非常小的模糊图像.缓存图像后,应显示直接全尺寸图像.
图像显示流程如下: - 如果是第一次下载图像,请首先下载小尺寸图像,然后下载全分辨率图像. - 如果之前已下载图像,则直接显示全尺寸图像.
我在Glide库中找不到任何方法,它告诉我缓存中是否存在文件.
任何想法,如何做到这一点.
我正在尝试imageView
通过Glide 将图像加载到其中。但是图像未加载-我收到错误消息。我正在使用以下代码
GlideApp.with(context)
.load(itemData.getThumbnailUri())
.placeholder(R.mipmap.koya_logo_white)
.error(R.mipmap.ic_image_loading_error)
.into(itemBinding.cover);
Run Code Online (Sandbox Code Playgroud)
日志
lide: Load failed for https://s3.amazonaws.com/koya-dev-videos/kindness/8da807aa-1e1e-413d-bf9b-5bb084646593/medialibrary/9456621508/videos/1eb78337-d569-41bd-95ad-153d9098de03.png with size [1080x1080]
Run Code Online (Sandbox Code Playgroud)
class com.bumptech.glide.load.engine.GlideException: Failed to load resource
Cause (1 of 1): class com.bumptech.glide.load.engine.GlideException: Failed LoadPath{StringUri->Object->Drawable}, LOCAL, DataCacheKey{sourceKey=https://s3.amazonaws.com/koya-dev-videos/kindness/8da807aa-1e1e-413d-bf9b-5bb084646593/medialibrary/9456621508/videos/1eb78337-d569-41bd-95ad-153d9098de03.png, signature=EmptySignature}
Cause (1 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{StringUri->Drawable->Drawable}
Cause (2 of 2): class com.bumptech.glide.load.engine.GlideException: Failed DecodePath{StringUri->Bitmap->Drawable}
Run Code Online (Sandbox Code Playgroud) 我在我的android项目中使用滑动库来获取和显示图像.之前我使用的是2.0.5版,面临渲染问题.问题是错误的图像呈现.我已将库更新到3.3版本,它现在崩溃,出现以下异常.
14-Sep-2014 08:41:31 PM java.lang.IllegalArgumentException:
You cannot start a load for a destroyed activity
at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:63)
at com.bumptech.glide.manager.RequestManagerRetriever.get(RequestManagerRetriever.java:29)
at com.bumptech.glide.Glide.with(Glide.java:537)
at com.miamiheat.common.MHImageDownloadWrapper.loadImage(MHImageDownloadWrapper.java:12)
at com.miamiheat.ui.module.MHWallpaperModule.setWallpaperViewData(MHWallpaperModule.java:234)
at com.miamiheat.ui.module.MHWallpaperModule.taskManagerResponseCallback(MHWallpaperModule.java:257)
at com.miamiheat.service.taskmanager.MHWallpaperTaskManager.asyncResultCallback(MHWallpaperTaskManager.java:133)
at com.miamiheat.service.framework.MHAsyncServiceTask.onPostExecute(MHAsyncServiceTask.java:191)
at android.os.AsyncTask.finish(AsyncTask.java:631)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
反正是否取消活动销毁的图像下载请求.
我正在尝试使用Glide逐步浏览视频文件中的帧(而不会遇到关键帧寻求Android遭受的问题).我可以通过以下方式在毕加索做到这一点:
picasso = new Picasso.Builder(MainActivity.this).addRequestHandler(new PicassoVideoFrameRequestHandler()).build();
picasso.load("videoframe://" + Environment.getExternalStorageDirectory().toString() +
"/source.mp4#" + frameNumber)
.placeholder(drawable)
.memoryPolicy(MemoryPolicy.NO_CACHE)
.into(imageView);
Run Code Online (Sandbox Code Playgroud)
(frameNumber只是一个int,每次增加50000微秒).我也有像这样的PicassoVideoFrameRequestHandler:
public class PicassoVideoFrameRequestHandler extends RequestHandler {
public static final String SCHEME = "videoframe";
@Override public boolean canHandleRequest(Request data) {
return SCHEME.equals(data.uri.getScheme());
}
@Override
public Result load(Request data, int networkPolicy) throws IOException {
FFmpegMediaMetadataRetriever mediaMetadataRetriever = new FFmpegMediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(data.uri.getPath());
String offsetString = data.uri.getFragment();
long offset = Long.parseLong(offsetString);
Bitmap bitmap = mediaMetadataRetriever.getFrameAtTime(offset, FFmpegMediaMetadataRetriever.OPTION_CLOSEST);
return new Result(bitmap, Picasso.LoadedFrom.DISK);
}
}
Run Code Online (Sandbox Code Playgroud)
我想改用Glide,因为它可以更好地处理内存.有没有办法在Glide中使用此功能?
或者,实际上,从视频中创建一组帧的任何其他方式,我可以单步执行!
谢谢!
如何使用Glide库将Bitmap加载到我的ImageView中?我想用文本创建自定义图像,并使用Glide将其加载到imageview中.
这是我用文本创建自定义位图的方法
public Bitmap imageWithText(String text) {
TextView tv = new TextView(context);
tv.setText(text);
tv.setTextColor(Color.WHITE);
tv.setBackgroundColor(Color.BLACK);
tv.setTypeface(null, Typeface.BOLD);
tv.setGravity(Gravity.CENTER);
tv.setTextSize(20);
tv.setPadding(0, 25, 0, 0);
Bitmap testB = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(testB);
tv.layout(0, 0, 100, 100);
tv.draw(c);
return testB;
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试使用滑动加载此位图时,我收到错误
Glide.with(getContext()).load(imageWithText("Random text")).into(holder.imgPhoto);
Run Code Online (Sandbox Code Playgroud) 我得到一些包含一些食物菜单项的JSON数据
请注意:这只是一个示例,有时会有超过2个图像,阵列中还有更多菜单项!
{
"menu": [
{
"url": "/api/v1/menu/1",
"name": "Best Food",
"description": "really nice food",
"opening_time": "every day from 9am to 6pm",
"contact_email": "info@food.com",
"tel_number": "+54 911 3429 5762",
"website": "http://bestfood.com",
"images": [
{
"url": "https://blahblah/image1.jpg"
},
{
"url": "https://blahblah/image2.jpg"
}
]
},
]
}
Run Code Online (Sandbox Code Playgroud)
每个项目都有一些信息和一组图像URL.
我正在使用Glide图像库来处理这些图像,并使用Retrofit 2.0从端点下载JSON数据.一切都很顺利.
但是,我需要存储此下载的数据以供离线访问.
目前,我在现有模型上使用ORM Lite将所有JSON数据存储在数据库中.这部分还可以.
但是,在我的数据库中,我只存储图像URL,因为我被告知在数据库中存储图像(作为blob)不是好方法.
因此,我的应用程序中有一个部分可以查看已保存的菜单,如果用户选择,可以选择将其下载以供脱机访问.
此时值得一提的是,我已经在数据库中拥有原始菜单信息,因为用户必须首先查看菜单才能在DB中获取它.
但问题是图像.
这是我不知道如何进行的地方,但我列出了我正在考虑的解决方案和问题,并希望人们可以告诉我什么是最好的行动方案.
使用服务下载图像.我认为这是强制性的,因为我不知道将有多少图像,即使用户退出应用程序,我也希望继续下载
Glide有一个仅下载图像选项,您可以在此处和此处阅读其配置缓存所在的位置(内部私有或外部公共).问题是我对设置缓存大小感到不舒服,因为我不知道需要什么.我想设置无限.
我需要能够删除保存的菜单数据,特别是如果它保存在外部公共目录中,因为在删除应用程序时不会删除该菜单数据,或者如果用户选择从应用程序中删除已保存的菜单.我以为我可以将文件图像URI或整个保存菜单的位置存储在数据库中,但不确定这是否是一种好方法
我在不同的来源和答案中读到,在这个用例中只是将图像缓存到SD卡等,我应该专门使用网络库来避免将位图分配给堆内存.我目前在我的应用程序中使用OK HTTP.
我使用滑翔3.7.0用RecyclerView
.刷新(调用notifyDataSetChanged
)时,项目视图始终闪烁.
这是我的代码:
Glide
.with(context)
.load(filepath)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.dontAnimate()
.into(imageview);
Run Code Online (Sandbox Code Playgroud)
当我不使用缓存时,在调用方法ImageView
时notifyDataSetChanged
Glide尚未完成加载位图时,它具有空位图.
如果我使用以下代码:
Glide
.with(context)
.load(filepath)
.dontAnimate()
.into(imageview);
Run Code Online (Sandbox Code Playgroud)
然后项目ImageView
不再闪烁(使用缓存).
我想动态更新项目视图,因此我禁用了滑动缓存.
有没有解决这个眨眼错误的解决方案?
非常感谢你!
android blink notifydatasetchanged android-recyclerview android-glide
我正在从毕加索转向格莱德.一切正常,除了我找不到一个方法来获得错误回调.我想检索一个Bitmap,传递它并从中生成一个Android Palette.此外,虽然可以将errorDrawable提供给加载调用,但在onResourceReady
使用时它不会显示SimpleTarget
.
在毕加索我做到了这样:
target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
//handle Bitmap, generate Palette etc.
}
@Override
public void onBitmapFailed(final Drawable errorDrawable) {
// use errorDrawable to generate Palette
}
@Override
public void onPrepareLoad(final Drawable placeHolderDrawable) {
}
};
int width = (int) DisplayUnitsConverter.dpToPx(this, 120);
int height = (int) DisplayUnitsConverter.dpToPx(this, 40);
Picasso.with(this).load(config.getPathToLogo()).resize(width, height).error(errorDrawableId).into(target);
Run Code Online (Sandbox Code Playgroud)
我的滑动代码如下所示:
Glide.with(context)
.load(config.getPathToLogo())
.asBitmap()
.into(new SimpleTarget<Bitmap>(width, height) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation glideAnimation) {
//handle …
Run Code Online (Sandbox Code Playgroud) 每当我尝试编译它时,我遇到这个项目的问题就会显示错误
错误:找不到符号类
GlideDrawable
请看看app:module
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support',
module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support:cardview-v7:27.0.2'
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support:design:27.0.2'
compile project(':SubProjects:lib_sound_crop')
compile project(':SubProjects:libraryColorPickrBest')
compile project(':SubProjects:library_gellaryfinal')
compile 'com.android.support:multidex:1.0.2'
implementation 'com.github.bumptech.glide:glide:4.6.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.0'
compile 'jp.wasabeef:glide-transformations:2.0.1'
compile 'com.google.firebase:firebase-messaging:11.8.0'
compile 'com.google.firebase:firebase-ads:11.8.0'
compile 'com.google.firebase:firebase-core:11.8.0'
testCompile 'junit:junit:4.12'
Run Code Online (Sandbox Code Playgroud)
和项目建设
buildscript {
repositories {
mavenCentral()
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.1'
}
Run Code Online (Sandbox Code Playgroud)
提前致谢
我只是尝试使用glide recyclerview集成并阅读有关它的文档,它说:" RecyclerView集成库使您的应用程序中可以使用RecyclerViewPreloader .RecyclerViewPreloader可以在用户在RecyclerView中滚动的位置之前自动加载图像 ",但是我没有意识到滑翔回收视图集成和滑行之间有什么区别,请说明滑行回收视图集成的进展是什么?我怎么能看出差异?
这是我的代码:
GlideModule.kt
@GlideModule
class GlideModule : AppGlideModule() {
override fun applyOptions(context: Context?, builder: GlideBuilder?) {
val requestOp = RequestOptions.noAnimation()
.priority(Priority.LOW)
builder?.setDefaultRequestOptions(requestOp)
?.setLogLevel(Log.VERBOSE)
super.applyOptions(context, builder)
}
// Disable manifest parsing to avoid adding similar modules twice.
override fun isManifestParsingEnabled(): Boolean {
return false
}
}
Run Code Online (Sandbox Code Playgroud)
MyPreloadModelProvide.kt
class MyPreloadModelProvide(val listUrls: List<String>, val context: Context) : PreloadModelProvider<Any> {
override fun getPreloadItems(position: Int): MutableList<Any> {
val url = listUrls.get(position)
if (TextUtils.isEmpty(url)) {
return Collections.emptyList();
}
return Collections.singletonList(url);
}
override …
Run Code Online (Sandbox Code Playgroud) android kotlin android-recyclerview recyclerview-layout android-glide