2014-02-14 45 views
2

我已经添加三个不同的bitmap到一个ImageView如下图所示。但问题是我无法编辑Bitmap设置为ImageView后。 我要拖动,滚动&放大个人BitmapImageView三角形ImageView与拖动,滚动和缩放onTouch Android

enter image description here

我对获得合并bitmap代码:

Bitmap setBitmapInTriangleShape(Bitmap bitmap1, Bitmap bitmap2, 
     Bitmap bitmap3) { 
    /* 
    * int[] values= new int[2]; mImageView.getLocationOnScreen(values); 
    */ 
    double screenHeightAspect = 2.5; 
    Bitmap drawnBitmap = null; 

    bitmap1 = Bitmap.createScaledBitmap(bitmap1, screenWidth, 
      (int) (screenHeight/screenHeightAspect), true); 
    bitmap2 = Bitmap.createScaledBitmap(bitmap2, screenWidth, 
      (int) (screenHeight/screenHeightAspect), true); 
    bitmap3 = Bitmap.createScaledBitmap(bitmap3, screenWidth, 
      (int) (screenHeight/screenHeightAspect), true); 

    try { 
     drawnBitmap = Bitmap 
       .createBitmap(screenWidth, 
         (int) (screenHeight/screenHeightAspect), 
         Config.ARGB_8888); 
     Canvas canvas = new Canvas(drawnBitmap); 
     canvas.drawColor(Color.TRANSPARENT); 

     // --------------------------------------------------------------- 
     Paint paint = new Paint(); 
     paint.setStrokeWidth(4); 
     paint.setColor(getResources().getColor(
       R.color.gray_divider_reg_edit_grid_1)); 
     paint.setStyle(Paint.Style.FILL_AND_STROKE); 

     Path path = new Path(); 
     BitmapShader bms = new BitmapShader(bitmap1, TileMode.CLAMP, 
       TileMode.CLAMP); 
     paint.setStyle(Style.FILL); 
     paint.setShader(bms); 
     // bms.setLocalMatrix(matrix); 

     // -----------------=for photo 1----------------------------- 
     path.reset(); 
     path.setFillType(Path.FillType.EVEN_ODD); 

     path.lineTo(0, 0); 
     path.lineTo((int) (screenWidth * 0.80), 0); 
     // path.lineTo(0, 15); 
     path.lineTo(0, (int) (screenHeight * 0.8706/screenHeightAspect)); 
     path.close(); 
     canvas.drawPath(path, paint); 

     Matrix mt = new Matrix(); 

     canvas.drawBitmap(bitmap1, new Matrix(), null); 
     // -------------------for photo 3----------------------------- 
     BitmapShader bmsUo = new BitmapShader(bitmap3, TileMode.CLAMP, 
       TileMode.CLAMP); 
     paint.setStyle(Style.FILL); 
     paint.setShader(bmsUo); 
     // bms.setLocalMatrix(matrix); 

     path.reset(); 
     path.setFillType(Path.FillType.EVEN_ODD); 
     path.moveTo((int) (screenWidth * 0.80), 0); 
     path.lineTo((int) (screenWidth * 0.80), 0); 
     path.lineTo(screenWidth, 0); 
     path.lineTo(screenWidth, (int) (screenHeight/screenHeightAspect)); 
     // path.lineTo(800,800); 
     path.lineTo((int) (screenWidth * 0.88), 
       (int) (screenHeight/screenHeightAspect)); 

     path.lineTo((int) (screenWidth * 0.50), 
       (int) (screenHeight * 0.32/screenHeightAspect)); 

     path.close(); 
     canvas.drawPath(path, paint); 

     // ---------------------for photo 2------------------------- 
     BitmapShader bmsUop = new BitmapShader(bitmap2, TileMode.CLAMP, 
       TileMode.CLAMP); 
     paint.setStyle(Style.FILL); 
     paint.setShader(bmsUop); 
     // bmsUop.setLocalMatrix(matrix); 
     path.reset(); 
     path.setFillType(Path.FillType.EVEN_ODD); 
     path.moveTo((int) (screenWidth * 0.50), 
       (int) (screenHeight * 0.32/screenHeightAspect)); 
     path.lineTo((int) (screenWidth * 0.50), 
       (int) (screenHeight * 0.32/screenHeightAspect)); 
     path.lineTo((int) (screenWidth * 0.88), 
       (int) (screenHeight/screenHeightAspect)); 
     path.lineTo(0, (int) (screenHeight/screenHeightAspect)); 
     path.lineTo(0, (int) (screenHeight/screenHeightAspect * 0.8706)); 

     path.close(); 
     canvas.drawPath(path, paint); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    return drawnBitmap; 

} 

任何帮助表示赞赏。

+2

是此画在画布上,并获取位图,然后将bitmpa设置为imageView – Triode

+1

你可以使用蒙版和画布来实现: http://stackoverflow.com/questions/14801075/android-how-to-apply-mask-on-imageview –

+0

你能显示在画布上绘制三角形图像的示例代码? @Rajesh CP – OAEI

回答

1

这里是如何从这个问题掩模图像

https://github.com/hotveryspicy/MaskImage

参考源例如

Masking(crop) image in frame

EDIT

在个别变焦和链路缩小你想要的这三个bitma PS在不同的布局(您需要进行自定义图像视图),所以试试下面的网址,描述了如何让自己的自定义布局(以三角形图像视图)等

https://github.com/thecodepath/android_guides/wiki/Defining-Custom-Views

+0

这是有帮助的...但不完全如我想要做的...我仍在努力获得图像的确切形状。当我完成时,我也会把代码放在里面。 – OAEI

+0

我已经更新了我的问题,并帮助我,如果你知道这个问题。 – OAEI