feat:Image localRes and base64 support animation image

This commit is contained in:
pengfei.zhou 2020-04-01 14:11:13 +08:00 committed by osborn
parent 2467c026b9
commit 3bbf671420
2 changed files with 11 additions and 22 deletions

View File

@ -15,8 +15,8 @@
*/ */
package pub.doric.shader; package pub.doric.shader;
import android.annotation.SuppressLint;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
@ -32,10 +32,8 @@ import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.DrawableImageViewTarget; import com.bumptech.glide.request.target.DrawableImageViewTarget;
import com.bumptech.glide.request.target.ImageViewTarget;
import com.bumptech.glide.request.target.SizeReadyCallback; import com.bumptech.glide.request.target.SizeReadyCallback;
import com.bumptech.glide.request.target.Target; import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.Transition;
import com.github.pengfeizhou.jscore.JSONBuilder; import com.github.pengfeizhou.jscore.JSONBuilder;
import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JSValue; import com.github.pengfeizhou.jscore.JSValue;
@ -146,6 +144,11 @@ public class ImageNode extends ViewNode<ImageView> {
private void loadImageUrl(String url) { private void loadImageUrl(String url) {
RequestBuilder<Drawable> requestBuilder = Glide.with(getContext()) RequestBuilder<Drawable> requestBuilder = Glide.with(getContext())
.load(url); .load(url);
loadIntoTarget(requestBuilder);
}
private void loadIntoTarget(RequestBuilder<Drawable> requestBuilder) {
try { try {
requestBuilder = requestBuilder.apply(new RequestOptions().override(Target.SIZE_ORIGINAL)); requestBuilder = requestBuilder.apply(new RequestOptions().override(Target.SIZE_ORIGINAL));
if (isBlur) { if (isBlur) {
@ -197,6 +200,8 @@ public class ImageNode extends ViewNode<ImageView> {
return false; return false;
} }
}).into(new DrawableImageViewTarget(mView) { }).into(new DrawableImageViewTarget(mView) {
@SuppressLint("MissingSuperCall")
@Override @Override
public void getSize(@NonNull SizeReadyCallback cb) { public void getSize(@NonNull SizeReadyCallback cb) {
cb.onSizeReady(SIZE_ORIGINAL, SIZE_ORIGINAL); cb.onSizeReady(SIZE_ORIGINAL, SIZE_ORIGINAL);
@ -247,8 +252,7 @@ public class ImageNode extends ViewNode<ImageView> {
if (!TextUtils.isEmpty(imageType) && !TextUtils.isEmpty(base64)) { if (!TextUtils.isEmpty(imageType) && !TextUtils.isEmpty(base64)) {
try { try {
byte[] data = Base64.decode(base64, Base64.DEFAULT); byte[] data = Base64.decode(base64, Base64.DEFAULT);
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); loadIntoTarget(Glide.with(getContext()).load(data));
view.setImageBitmap(bitmap);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -271,22 +275,7 @@ public class ImageNode extends ViewNode<ImageView> {
"drawable", "drawable",
getDoricContext().getContext().getPackageName()); getDoricContext().getContext().getPackageName());
if (resId > 0) { if (resId > 0) {
Drawable drawable = getContext().getResources().getDrawable(resId); loadIntoTarget(Glide.with(getContext()).load(resId));
view.setImageResource(resId);
if (!TextUtils.isEmpty(loadCallbackId)) {
if (drawable instanceof BitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
callJSResponse(loadCallbackId, new JSONBuilder()
.put("width", DoricUtils.px2dp(bitmap.getWidth()))
.put("height", DoricUtils.px2dp(bitmap.getHeight()))
.toJSONObject());
} else {
callJSResponse(loadCallbackId, new JSONBuilder()
.put("width", DoricUtils.px2dp(drawable.getIntrinsicWidth()))
.put("height", DoricUtils.px2dp(drawable.getIntrinsicHeight()))
.toJSONObject());
}
}
} else { } else {
if (!TextUtils.isEmpty(loadCallbackId)) { if (!TextUtils.isEmpty(loadCallbackId)) {
callJSResponse(loadCallbackId); callJSResponse(loadCallbackId);

View File

@ -197,7 +197,7 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
} }
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64 NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64
options:NSDataBase64DecodingIgnoreUnknownCharacters]; options:NSDataBase64DecodingIgnoreUnknownCharacters];
UIImage *image = [UIImage imageWithData:imageData]; YYImage *image = [YYImage imageWithData:imageData];
view.image = image; view.image = image;
} else if ([@"isBlur" isEqualToString:name]) { } else if ([@"isBlur" isEqualToString:name]) {
NSInteger value = [prop intValue]; NSInteger value = [prop intValue];