Android ???????????? ( ?????? ) ??????????????????---Fresco
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android ???????????? ( ?????? ) ??????????????????---Fresco相关的知识,希望对你有一定的参考价值。
?????????RoCE -o hierarchy ?????? storage oca ?????? inter getheight
??????Fresco???Facebook?????????????????????android???????????????????????????????????????????????????????????????????????????????????????????????????????????????Gif??????WebP??????????????????
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????Fresco???????????????????????????https://www.fresco-cn.org/
??????Fresco GitHub ?????????https://github.com/facebook/fresco
Fresco??????
??????1.????????????
compile ???com.facebook.fresco:fresco:1.10.0???
????????????????????????
compile ???com.facebook.fresco:animated-gif:1.5.0???//??????gif????????????????????? compile ???com.facebook.fresco:animated-webp:1.5.0???//??????webp????????????????????? compile ???com.facebook.fresco:webpsupport:1.5.0???//??????webp??????????????? compile ???com.facebook.fresco:imagepipeline-okhttp3:1.5.0???//?????????????????????okhttp3??????????????? compile ???jp.wasabeef:fresco-processors:[email protected]???//????????????fresco?????????????????????
??????2.????????????????????????
??????????????????layout_width???layout_height????????????????????????????????????????????????SimpleDraweeView?????????wrap_content????????????????????????????????????wrap_content????????? ?????????????????????????????????match_parent
????????????
<com.facebook.drawee.view.SimpleDraweeView android:id="@+id/sdv_fresco" android:layout_width="130dp" android:layout_gravity="center" android:layout_height="130dp" fresco:placeholderImage="@drawable/atguigu_logo" />
??????3.????????????
??????3.1 ?????????????????????
??????// ???????????? GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(getResources()); GenericDraweeHierarchy hierarchy = builder.setProgressBarImage(new ProgressBarDrawable()).build(); sdvFresco.setHierarchy(hierarchy); // ????????????????????? Uri uri = Uri.parse("http://"); // ???????????? sdvFresco.setImageURI(uri);
??????3.2 ?????????????????????
????????????CENTER
??????GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(getResources()); //?????????????????? GenericDraweeHierarchy hierarchy = builder.setActualImageScaleType(ScalingUtils.ScaleType.CENTER).build();// ???????????? sdvFresco.setHierarchy(hierarchy); // ????????????????????? Uri uri = Uri.parse("http://"); // ???????????? sdvFresco.setImageURI(uri);
??????CENTER_CROP
//?????????????????????????????????????????????????????????????????????????????????????????? GenericDraweeHierarchy hierarchy = builder.setActualImageScaleType(ScalingUtils.ScaleType.CENTER_CROP).build();
??????FOCUS_CROP
// ???centerCrop, ???????????????????????????????????????????????????,?????????????????????????????????????????? PointF point = new PointF(0,0); GenericDraweeHierarchy hierarchy = builder.setActualImageScaleType(ScalingUtils.ScaleType.FOCUS_CROP)
??????CENTER_INSIDE
//?????????????????????????????????????????????????????????????????????????????????????????????????????????????????? GenericDraweeHierarchy hierarchy = builder.setActualImageScaleType(ScalingUtils.ScaleType.CENTER_INSIDE).build();
??????FIT_CENTER
//???????????????????????????????????????????????????????????????????????????????????????????????? GenericDraweeHierarchy hierarchy = builder.setActualImageScaleType(ScalingUtils.ScaleType.FIT_CENTER).build();
??????FIT_START
//??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? GenericDraweeHierarchy hierarchy = builder.setActualImageScaleType(ScalingUtils.ScaleType.FIT_START).build();
??????FIT_END
//??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? GenericDraweeHierarchy hierarchy = builder.setActualImageScaleType(ScalingUtils.ScaleType.FIT_END).build();
??????FIT_XY
//?????????????????????????????????????????? GenericDraweeHierarchy hierarchy = builder.setActualImageScaleType(ScalingUtils.ScaleType.FIT_XY).build();
??????title mode
//????????????title mode??????, ???????????????none GenericDraweeHierarchy hierarchy = builder.setActualImageScaleType(null).build();
??????3.3 ???????????????????????????
??????//???????????? parames = RoundingParams.asCircle(); GenericDraweeHierarchy hierarchy = builder.setRoundingParams(parames).build(); //???????????? parames = RoundingParams.fromCornersRadius(50f); //parames.setOverlayColor(getResources().getColor(android.R.color.holo_red_light));//????????? //parames.setBorder(getResources().getColor(android.R.color.holo_blue_light), 5);//?????? GenericDraweeHierarchy hierarchy = builder.setRoundingParams(parames).build();
??????3.4 ?????????????????????
??????// ?????????????????? ProgressiveJpegConfig jpegConfig = new ProgressiveJpegConfig() { @Override public int getNextScanNumberToDecode(int scanNumber) { return scanNumber + 2; } @Override public QualityInfo getQualityInfo(int scanNumber) { boolean isGoodEnough = (scanNumber >= 5); return ImmutableQualityInfo.of(scanNumber, isGoodEnough, false); } }; ImagePipelineConfig.newBuilder(this).setProgressiveJpegConfig(jpegConfig).build(); // ????????????URL Uri uri = Uri.parse("http://"); // ?????????????????? ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri).setProgressiveRenderingEnabled(true).build(); DraweeController draweeController = Fresco.newDraweeControllerBuilder() .setImageRequest(request) .setTapToRetryEnabled(true) .setOldController(sdvFresco.getController())//??????oldController???????????????????????????????????? .build(); // ????????????????????? sdvFresco.setController(draweeController);
??????3.5 GIF????????????
??????Uri uri = Uri.parse("http://"); DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(uri) .setAutoPlayAnimations(true) //?????????????????? .setOldController(sdvFresco.getController()) .build(); sdvFresco.setController(controller); // ???????????? Animatable animatable = sdvFresco.getController().getAnimatable(); if(animatable != null && !animatable.isRunning()) { animatable.start(); } //???????????? Animatable animatable = sdvFresco.getController().getAnimatable(); if(animatable != null && animatable.isRunning()) { animatable.stop(); }
??????3.6 ???????????????????????????
?????????????????????????????????????????????????????????????????????
??????// ???????????? Uri lowUri = Uri.parse("http://"); Uri highUri = Uri.parse("http://"); // ?????????????????? DraweeController controller = Fresco.newDraweeControllerBuilder() .setLowResImageRequest(ImageRequest.fromUri(lowUri)) .setImageRequest(ImageRequest.fromUri(highUri)) .build(); // ???????????? sdvFresco.setController(controller); ????????????????????? // ???????????? Uri uri = Uri.fromFile(new File(Environment.getExternalStorageDirectory() +"/meinv1.jpg")); // ????????????????????? ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri) .setLocalThumbnailPreviewsEnabled(true) .build(); // ????????????????????? DraweeController controller = Fresco.newDraweeControllerBuilder() .setImageRequest(request) .build(); // ???????????? sdvFresco.setController(controller); ?????????????????? //????????????????????? //???????????????????????????????????????????????????????????????????????????????????????????????????uri //???????????????????????????uri ???????????????????????????????????????????????????????????????uri // ?????????????????? Uri uri1 = Uri.fromFile(new File(Environment.getExternalStorageDirectory()+"/meinv.jpg")); //???????????????uri Uri uri2 = Uri.parse("http://"); ImageRequest request1 = ImageRequest.fromUri(uri1); ImageRequest request2 = ImageRequest.fromUri(uri2); ImageRequest[] requests = {request1, request2}; // ?????????????????? DraweeController controller = Fresco.newDraweeControllerBuilder() .setFirstAvailableImageRequests(requests) .setOldController(sdvFresco.getController()) .build(); // ???????????? sdvFresco.setController(controller);
??????3.7 ??????????????????
// ????????????????????? //?????????????????? .setControllerListener(controllerListener) SimpleDraweeView sdvFrescoListener; DraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(sdvFrescoListener.getController()) .setImageRequest(request) .setControllerListener(controllerListener) .build();
private ControllerListener controllerListener = new BaseControllerListener<ImageInfo>(){ // ?????????????????? @Override public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) { super.onFinalImageSet(id, imageInfo, animatable); if (imageInfo == null) { return; } // ????????????????????? QualityInfo qualityInfo = imageInfo.getQualityInfo(); //??????????????????setText tvFrescoListener.setText("Final image received! " + " Size: " + imageInfo.getWidth() + "x" + imageInfo.getHeight() + " Quality level: " + qualityInfo.getQuality() + " good enough: " + qualityInfo.isOfGoodEnoughQuality() + " full quality: " + qualityInfo.isOfFullQuality()); } // ??????????????????????????? @Override public void onIntermediateImageSet(String id, ImageInfo imageInfo) { super.onIntermediateImageSet(id, imageInfo); tvFrescoListener2.setText("IntermediateImageSet image receiced"); } // ?????????????????? @Override public void onFailure(String id, Throwable throwable) { super.onFailure(id, throwable); tvFrescoListener.setText("Error loading" + id); } }
??????3.8 ?????????????????????
??????????????????????????????????????? setResizeOptions
??????// ???????????? Uri uri = Uri.parse("http://"); // ??????????????? ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri) .setResizeOptions(new ResizeOptions(50,50)) .build(); // ????????????????????? PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder() .setOldController(sdvFresco.getController()) .setImageRequest(request) .build(); // ???????????? sdvFresco.setController(controller);
???????????????????????? setAutoRotateEnabled
??????Uri uri = Uri.parse("http://"); ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri) .setAutoRotateEnabled(true) .build(); // ????????????????????? DraweeController controller = Fresco.newDraweeControllerBuilder() .setOldController(sdvFresco.getController()) .setImageRequest(request) .build(); // ???????????? sdvFresco.setController(controller);
??????3.9 ????????????(??????????????????,???????????????ImageRequest??????) setPostprocessor
// ???????????? Postprocessor postProcessor = new BasePostprocessor() { @Override public String getName() { return "postProcessor"; } @Override public void process(Bitmap bitmap) { for (int x = 0; x < bitmap.getWidth(); x += 2) { for (int y = 0; y < bitmap.getHeight(); y += 2) { bitmap.setPixel(x, y, Color.RED); } } } }; // ?????????????????? ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri) .setPostprocessor(postProcessor) .build();
??????3.10 ???????????????????????????SimpleDraweeView???LinearLayout??????
??????SimpleDraweeView simpleDraweeView = new SimpleDraweeView(this); // ??????????????? simpleDraweeView.setAspectRatio(3.0f); // ??????????????? Uri uri = Uri.parse("http://"); // ??????????????? ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri) .build(); // ????????????????????? PipelineDraweeController controller = (PipelineDraweeController) Fresco.newDraweeControllerBuilder() .setOldController(simpleDraweeView.getController()) .setImageRequest(request) .build(); // ???????????? simpleDraweeView.setController(controller); // ??????View?????????????????? linearLayout.addView(simpleDraweeView);
以上是关于Android ???????????? ( ?????? ) ??????????????????---Fresco的主要内容,如果未能解决你的问题,请参考以下文章
Android 逆向Android 权限 ( Android 逆向中使用的 android.permission 权限 | Android 系统中的 Linux 用户权限 )