Closed gyqsophila closed 6 years ago
能给个demo吗?非常感谢。
调用代码么?
@Override
public void onThumbPictureClick(ImageView i, List<ImageView> imageGroupList, List<String> urlList) {
vImageWatcher.show(i, imageGroupList, urlList);
}
出问题的图片就是分辨路 6000*4000,大小 2.7M,别的图片没问题的
@Override
public void onResourceReady(Bitmap resource) {
final int sourceDefaultWidth, sourceDefaultHeight, sourceDefaultTranslateX, sourceDefaultTranslateY;
int resourceImageWidth = resource.getWidth();
int resourceImageHeight = resource.getHeight();
if (resourceImageWidth * 1f / resourceImageHeight > mWidth * 1f / mHeight) {
sourceDefaultWidth = mWidth;
sourceDefaultHeight = (int) (sourceDefaultWidth * 1f / resourceImageWidth * resourceImageHeight);
sourceDefaultTranslateX = 0;
sourceDefaultTranslateY = (mHeight - sourceDefaultHeight) / 2;
imageView.setTag(R.id.image_orientation, "horizontal");
} else {
sourceDefaultHeight = mHeight;
sourceDefaultWidth = (int) (sourceDefaultHeight * 1f / resourceImageHeight * resourceImageWidth);
sourceDefaultTranslateY = 0;
sourceDefaultTranslateX = (mWidth - sourceDefaultWidth) / 2;
imageView.setTag(R.id.image_orientation, "vertical");
}
imageView.setImageBitmap(resource);
notifyItemChangedState(pos, false, false);
ViewState vsDefault = ViewState.write(imageView, ViewState.STATE_DEFAULT).width(sourceDefaultWidth).height(sourceDefaultHeight)
.translationX(sourceDefaultTranslateX).translationY(sourceDefaultTranslateY);
if (isPlayEnterAnimation) {
animSourceViewStateTransform(imageView, vsDefault);
} else {
ViewState.restore(imageView, vsDefault.mTag);
imageView.setAlpha(0f);
imageView.animate().alpha(1).start();
}
}
看了一下,应该是我的问题吧,没有考虑 图片大小超过了屏幕尺寸的情况。
好的 ,我会调试的, 可能几天,十几天更新。
@AlphaGao1993 在 imageView.setImageBitmap(resource);
之前,应该对resource
的大小先处理一下吧。我应该漏了这里。 你是导入源码方式使用的吗? 对不起 还是我自己太菜了
我本地也有 Glide ,直接拷贝的源码,这个组件还是挺好的,我反正写不出来,你还是挺厉害的
那你可以调试 断点 onResourceReady 开始。 还有 为什么会加载2.7M的网络图。 我感觉这件事件本身就有点不对吧。 加载的图片url应该都是自己控制过后上传给后台的吧。
/**
* 图片辅助工具 提供压缩和上传功能
*/
class PictureHelper {
companion object {
fun compress(originUrl: String): Publisher<String> {
return Publisher { s ->
Tiny.getInstance().source(File(originUrl)).asFile().compress { isSuccess, outfile ->
if (isSuccess) {
s.onNext(outfile)
} else {
Toast.makeText(App.get(), "源文件受损或内存不足导致压缩失败,请重试或换一张\n" + originUrl, Toast.LENGTH_SHORT).show()
}
s.onComplete()
}
}
}
fun upload(uploadUrl: String, ti: PictureUploadTokenInfo,
upProgressHandler: UpProgressHandler = UpProgressHandler { _, percent -> EventBus.getDefault().post(BusEvent(Bus.PICTURE_UPLOADING, uploadUrl, percent)) }): Publisher<String> {
return Publisher { s ->
UploadManager().put(File(uploadUrl), null, ti.token, { _, _, response ->
val remoteUrl = "http://" + ti.site + "/" + response.getString("key")
Const.logd("PictureHelper upload resp $remoteUrl ${response.getString("key")}")
s.onNext(remoteUrl)
s.onComplete()
}, UploadOptions(null, null, false, upProgressHandler, null))
}
}
}
}
// 大图上传
val data = arrayOf("/storage/emulated/0/DCIM/Camera/LYY_8843.JPG", "/storage/emulated/0/DCIM/Camera/LYY_8841.JPG", "/storage/emulated/0/DCIM/Camera/LYY_8818.JPG", "/storage/emulated/0/DCIM/Camera/LYY_8850.JPG", "/storage/emulated/0/DCIM/Camera/LYY_8846.JPG", "/storage/emulated/0/DCIM/Camera/LYY_8822.JPG", "/storage/emulated/0/DCIM/Camera/LYY_8829.JPG", "/storage/emulated/0/DCIM/Camera/LYY_8821.JPG", "/storage/emulated/0/DCIM/Camera/LYY_8839.JPG")
val pictureUrlList = Arrays.asList(*data)
Flowable.create(FlowableOnSubscribe<String> { e ->
for (originUrl in pictureUrlList) {
e.onNext(originUrl)
}
e.onComplete()
}, BackpressureStrategy.BUFFER)
.flatMap { originUrl -> PictureHelper.compress(originUrl) }
.flatMap { compressedUrl -> PictureHelper.upload(compressedUrl, o) }
.subscribe(object : Subscriber<String> {
internal lateinit var subscription: Subscription
override fun onSubscribe(s: Subscription) {
Const.logd("onSubscribe")
subscription = s
s.request(2)
}
override fun onNext(s: String) {
Const.logd("onNext " + s)
subscription.request(2)
}
override fun onError(t: Throwable) {
Const.loge("onError " + t.message)
}
override fun onComplete() {
Const.logd("onComplete")
}
})
'com.qiniu:qiniu-android-sdk:7.3.3'
上传
'com.zxy.android:tiny:0.0.6'
压缩
ps:题外话, 批量压缩上传图片代码分享
@ielse 兄弟你真是太好心了~
我更希望你们大家都能帮忙改代码,也会自己改呀。祝你越来越强
@ielse 好的
@AlphaGao1993
https://github.com/bumptech/glide/issues/547
If you're loading into SimpleTarget, notice that the implicit size in the default constructor is SIZE_ORIGINAL, try a more reasonable size in the overloaded constructor.
这个问题是加载的图片太大了,hold不住的原因吧。
https://github.com/bumptech/glide/issues/2313
现在 ImageWatcher.Loader
被抽出来啦,你可以预先设定对应uri所加载的宽高。
方案如2313
。
但其实更优的方案应是加载的uri图片本身尺寸就是适合手机的尺寸 比如 https://developer.qiniu.com/dora/manual/1279/basic-processing-images-imageview2
W/OpenGLRenderer: Bitmap too large to be uploaded into a texture (6000x4000, max=4096x4096)