0

Fresco, yuvarlak görüntüler ve yuvarlak köşeler için yerleşik desteğe sahiptir, ancak elmas veya paralelkenar vb. Gibi diğer şekillere ne dersiniz?Android Fresco: Farklı türde resim şekilleri çizme

Standart ImageView ile, BitmapShader kullanan özel çekilebilir bağlantı ile yapılması basittir.

enter image description here

public class MaskDrawable extends Drawable { 
    private Paint mPaint; 
    private Path mPath; 
    private int mSlopeHeight; 

    public MaskDrawable(Bitmap bitmap, int slopeHeight) { 
     BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); 
     mPaint = new Paint(); 
     mPaint.setAntiAlias(true); 
     mPaint.setShader(shader); 
     mSlopeHeight = slopeHeight; 

     mPath = new Path(); 
    } 

    @Override 
    public void draw(Canvas canvas) { 
     Rect bounds = getBounds(); 

     mPath.moveTo(0, 0); 
     mPath.lineTo(0, bounds.bottom); 
     mPath.lineTo(bounds.right, bounds.bottom - mSlopeHeight); 
     mPath.lineTo(bounds.right, 0); 
     canvas.drawPath(mPath, mPaint); 
    } 

Fresco ile, ben görüntünün Bitmap gerektiğini yapmak için: Örneğin, aşağıdaki özel Drawable görüntü Bitmap ve bu resim gibi bir bir ImageView görünmesi için bir eğim yüksekliği alır ama bunu nasıl yapacağımı bilmiyorum. Bitmap'i doğrudan ImagePipeline'dan alabildiğimi okudum, fakat bununla birlikte gelen çok sayıda tuhaflık var. Bir durumda, döndürülmüş Bitmap kısa ömürlüdür ve diğer durumda, bana açık olmayan bir noktada serbest bırakmam gereken bir CloseableReference elde etmek için ekranda kullanılmamalıdır. Bunu henüz denemedim ve biri yerine bit ve bayt ben bir çalışma çözüm sağlayabilir acaba

ImagePipeline imagePipeline = Fresco.getImagePipeline(); 

     ImageRequest imageRequest = ImageRequestBuilder 
       .newBuilderWithSource(uri) 
       .setRequestPriority(Priority.HIGH) 
       .setLowestPermittedRequestLevel(ImageRequest.RequestLevel.FULL_FETCH) 
       .build(); 

     DataSource<CloseableReference<CloseableBitmap>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, getContext()); 

     DataSubscriber<CloseableReference<CloseableBitmap>> dataSubscriber = 
       new BaseDataSubscriber<CloseableReference<CloseableBitmap>>() { 
        @Override 
        protected void onNewResultImpl(DataSource<CloseableReference<CloseableBitmap>> dataSource) { 
         mBitmapRef = dataSource.getResult(); 
         // Get the bitmap here and use it in my custom drawable? 
        } 

        @Override 
        protected void onFailureImpl(DataSource<CloseableReference<CloseableBitmap>> dataSource) { 
        } 
       }; 

     dataSource.subscribe(dataSubscriber, UiThreadImmediateExecutorService.getInstance()); 

: Ne net gördük bugüne kadar Bitmap almak için buna benzer bir koddur farklı yerlerden bugüne kadar toplandı. Doğru yapılmalı ya da ilk önce Fresco'yu kullanma fikrini döven hafızaları kolayca akıtabiliyorum.

cevap

-1

Görüntü ile ilgilenirken, imagepipeline'ı kullanmanıza da gerek yoktur.

Bir yol, işlemcideki bu bitmap'i yönetmektir. Işlem yöntemini geçersiz kılmanız gerekir, aynı BitmapShader, boya, tuval uygulama kullanın, temizlenebilir bitmap CloseableReference oluşturmak için PlatformBitmapFactory createBitmap kullanın ve bitmap ile bittiğinde son olarak kapatın.

daha http://frescolib.org/docs/modifying-image.html

EDIT'e

yılında Aşağıda ben Jie Wang yardım aldıktan sonra geldi nihai uygulamasıdır bakın. Aşağıdaki kod parçacığı, görüntüyü soruda sunma biçiminde yerleştirir.

mSimpleDraweeView = (SimpleDraweeView) findViewById(R.id.shaped_picture); 
final int slopeHeight = 100; 

Postprocessor maskProcessor = new BasePostprocessor() { 
    @Override 
    public CloseableReference<Bitmap> process(Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) { 
     // Get the size of the downloaded bitmap 
     final int width = sourceBitmap.getWidth(); 
     final int height = sourceBitmap.getHeight(); 

     // Create a new bitmap and use it to draw the shape that we want. 
     CloseableReference<Bitmap> bitmapRef = bitmapFactory.createBitmap(width, height); 
     try { 
      Bitmap destBitmap = bitmapRef.get(); 

      // Create canvas using the new bitmap we created earlier 
      Canvas canvas = new Canvas(destBitmap); 

      // Set up the Paint we will use for filling in the shape 
      // BitmapShader will fill the shape with the downloaded bitmap 
      BitmapShader shader = new BitmapShader(sourceBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); 
      Paint paint = new Paint(); 
      paint.setAntiAlias(true); 
      paint.setShader(shader); 

      // Set up the actual shape. Modify this part with any shape you want to have. 
      Path path = new Path(); 
      path.moveTo(0, 0); 
      path.lineTo(0, height); 
      path.lineTo(width, height - slopeHeight); 
      path.lineTo(width, 0); 

      // Draw the shape and fill it with the paint 
      canvas.drawPath(path, paint); 

      return CloseableReference.cloneOrNull(bitmapRef); 
     } 
     finally { 
      CloseableReference.closeSafely(bitmapRef); 
     } 
    } 
}; 

ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri) 
     .setPostprocessor(maskProcessor) 
     .build(); 

DraweeController controller = Fresco.newDraweeControllerBuilder() 
     .setImageRequest(request) 
     .setOldController(mSimpleDraweeView.getController()) 
     .build(); 

mSimpleDraweeView.setController(controller); 
+0

Başkalarının bu soruna çarpması durumunda somut çözüm uygulamasına sahip olmak için cevabı güncelledim. –

İlgili konular