开发者

Is it possible to draw 2 Rect and excerpt the first?

EDIT: --> HEY GUYS! <--

i am working on an "Image based App"! What i want to do is:

  1. Take a photo (done)
  2. preview the Photo with an Overlay!
  3. Crop the Photo

So the problem is the Overlay! I have an SurfaceView with the taken Photo inside and now i want to see a square like a window (rect2) and around an alpha overlay (rect1 some kind of black with alpha 50%). Is it possible to draw 2 Rect, one in full size (rect1) and one in a smaller size (rect2) and then cut the smaller out of the first Rect??

______________
|Rect1       |
|   ______   |
|  |Rect2 |  |
|  |      |  |
|  |______|  |
|____________| 

I am using Android 2.1. I know in 2.3.3 there is an BitmapRegionDecoder! this thing does almost what i want to do. At the moment i draw 4 Rect and leave a smal hole in the middle for the window but it is like an pain in my A** to move this sqare and resizing it.

EDIT: What i want to do is like in Facebook, if you upload a picture as Profileimage you have to move a开发者_运维技巧nd resize a square on your image for the "avatar"-image on the left when you post something...

So i hope everything is clear and you can help me!

Thanks


You can use a FrameLayout, like container, and for positioning your SurfaceView (your rect). And with a removeView you can delete the rect you want, by capturing with a findviewbyid.

I hope this help you. bye


public class yourActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(new yourCanvas(this));
}

class yourCanvas extends View {
    public Panel(Context context) {
        super(context);
    }

    @Override
    public void onDraw(Canvas canvas) {
        Bitmap yourBitmap = getYourBitmap();
        canvas.drawBitmap(_yourBitmap, 50, 50, null);
        canvas.drawRect(0,0,canvas.getWidth(),50,null); //top rect
        canvas.drawRect(0,0,50,canvas.getHeight(),null); //left rect
        canvas.drawRect(50+yourBitmap.getWidth(),0,canvas.getWidth(),canvas.getHeight(),null); //right rect
        canvas.drawRect(0,50+yourBitmap.getHeight(),canvas.getWidth(),canvas.getHeight(),null); //Bottom rect
    }
}

}


previous answer suitable if you just want to create a border for your imageview

I would like to propose the following:

  1. setting an ImageView's bitmap to your bitmap
  2. setting the background color to the color you want the outer rect to be
  3. setting the padding parameters to get the desired dimensions
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜