首页 文章 精选 留言 我的

精选列表

搜索[内存超频],共10000篇文章
优秀的个人博客,低调大师

Matisse预览图片黑屏,Glide内存溢出

项目中要到图片、视频选择的功能,然后google了一下,找到Matisse,知乎的图片选择框架,用的人还挺多的,果断依赖gradle,然后开始我的踩坑之旅。 首先,框架本身的图片框架glide是v3版本的,然后我项目中的是目前最新的v4.7.1,然后需要重写它的图片加载.imageEngine(new GlideEngine()),因为低版本的一些api在高版本已经找不到了,这都是小问题。 public class GlideEngine implements ImageEngine{ @Override public void loadThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, Uri uri) { Glide.with(context) .asBitmap() // some .jpeg files are actually gif .load(uri) .apply(new RequestOptions() .override(resize, resize) .placeholder(placeholder) .centerCrop()) .into(imageView); } @Override public void loadGifThumbnail(Context context, int resize, Drawable placeholder, ImageView imageView, Uri uri) { Glide.with(context) .asBitmap() // some .jpeg files are actually gif .load(uri) .apply(new RequestOptions() .override(resize, resize) .placeholder(placeholder) .centerCrop()) .into(imageView); } @Override public void loadImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri) { Glide.with(context) .load(uri) .apply(new RequestOptions() .override(resizeX, resizeY) .priority(Priority.HIGH) .fitCenter()) .into(imageView); } @Override public void loadGifImage(Context context, int resizeX, int resizeY, ImageView imageView, Uri uri) { Glide.with(context) .asGif() .load(uri) .apply(new RequestOptions() .override(resizeX, resizeY) .priority(Priority.HIGH) .fitCenter()) .into(imageView); } @Override public boolean supportAnimatedGif() { return true; } } 然后运行成功,如愿以偿的打开了相册,当然这都建立了你已经申请并获得了6.0以上的运行期权限,Matisse图片加载器修改后,预览图片直接黑屏: Glide: Root cause (1 of 5) java.lang.OutOfMemoryError: Failed to allocate a 19660812 byte allocation with 13530040 free bytes and 12MB until OOM Glide: Root cause (4 of 5) java.io.IOException: java.lang.RuntimeException: setDataSource failed: status = 0x80000000 然后我下载了一份github上的代码,发现了Demo和GitHub上示例代码的问题。 Matisse.from(SampleActivity.this) .choose(MimeType.ofAll(), false) .countable(true) .capture(true) .captureStrategy( new CaptureStrategy(true, "com.zhihu.matisse.sample.fileprovider")) .maxSelectable(9) .addFilter(new GifSizeFilter(320, 320, 5 * Filter.K * Filter.K)) .gridExpectedSize( getResources().getDimensionPixelSize(R.dimen.grid_expected_size)) .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) .thumbnailScale(0.85f) // .imageEngine(new GlideEngine()) // for glide-V3 .imageEngine(new Glide4Engine()) // for glide-V4 .setOnSelectedListener(new OnSelectedListener() { @Override public void onSelected( @NonNull List<Uri> uriList, @NonNull List<String> pathList) { // DO SOMETHING IMMEDIATELY HERE Log.e("onSelected", "onSelected: pathList=" + pathList); } }) .originalEnable(true) .maxOriginalSize(10) .setOnCheckedListener(new OnCheckedListener() { @Override public void onCheck(boolean isChecked) { // DO SOMETHING IMMEDIATELY HERE Log.e("isChecked", "onCheck: isChecked=" + isChecked); } }) .forResult(REQUEST_CODE_CHOOSE); 在.addFilter(new GifSizeFilter())中GifSizeFilter这个类居然不是public的,在按照github上的示例代码时这行代码报错了,当时我以为是不太重要的代码,然后去掉了。 /* * Copyright 2017 Zhihu Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.zhihu.matisse.sample; import android.content.Context; import android.graphics.Point; import com.zhihu.matisse.MimeType; import com.zhihu.matisse.filter.Filter; import com.zhihu.matisse.internal.entity.IncapableCause; import com.zhihu.matisse.internal.entity.Item; import com.zhihu.matisse.internal.utils.PhotoMetadataUtils; import java.util.HashSet; import java.util.Set; class GifSizeFilter extends Filter { private int mMinWidth; private int mMinHeight; private int mMaxSize; GifSizeFilter(int minWidth, int minHeight, int maxSizeInBytes) { mMinWidth = minWidth; mMinHeight = minHeight; mMaxSize = maxSizeInBytes; } @Override public Set<MimeType> constraintTypes() { return new HashSet<MimeType>() {{ add(MimeType.GIF); }}; } @Override public IncapableCause filter(Context context, Item item) { if (!needFiltering(context, item)) return null; Point size = PhotoMetadataUtils.getBitmapBound(context.getContentResolver(), item.getContentUri()); if (size.x < mMinWidth || size.y < mMinHeight || item.size > mMaxSize) { return new IncapableCause(IncapableCause.DIALOG, context.getString(R.string.error_gif, mMinWidth, String.valueOf(PhotoMetadataUtils.getSizeInMB(mMaxSize)))); } return null; } } 最后的解决办法是复制了GifSizeFilter 并把它申明为public,问题解决。

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册