是否可以绘制 2 个矩形并摘录第一个矩形?

发布于 2024-11-28 10:55:20 字数 689 浏览 1 评论 0原文

编辑:-->嘿伙计们! <--

我正在开发一个“基于图像的应用程序”! 我想做的是:

  1. 拍照(完成)
  2. 预览带有叠加层的照片!
  3. 裁剪照片

所以问题是叠加!我有一个 SurfaceView,里面有拍摄的照片,现在我想看到一个像窗口一样的正方形(矩形 2),周围有一个 alpha 覆盖层(矩形 1 是某种黑色,透明度为 50%)。 是否可以绘制 2 个矩形,一个是全尺寸的(矩形 1),一个是较小尺寸的(矩形 2),然后从第一个矩形中切出较小的矩形?

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

我使用的是安卓2.1。我知道2.3.3中有一个BitmapRegionDecoder!这件事几乎完成了我想做的事情。 目前,我画了 4 个矩形,并在中间留了一个小洞作为窗口,但移动这个正方形并调整它的大小就像我的 A** 中的一个痛苦。

编辑:我想做的就像在 Facebook 中一样,如果您将图片上传为个人资料图片,则当您发布某些内容时,您必须移动图片上的一个正方形并调整其大小,以获得左侧的“头像”图片......

所以我希望一切都清楚了,你可以帮助我!

谢谢

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 and 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

○愚か者の日 2024-12-05 10:55:20

您可以使用 FrameLayout(如容器)来定位 SurfaceView(您的矩形)。
使用removeView,您可以通过使用findviewbyid 捕获来删除所需的矩形。

我希望这对你有帮助。再见

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

终陌 2024-12-05 10:55:20
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
    }
}


如果您只想为图像视图创建边框,

之前的答案适合我想建议以下内容:

  1. 设置 ImageView 的位图到您的位图,
  2. 将背景颜色设置为您希望外部矩形设置的颜色,设置
  3. 填充参数以获得所需的尺寸
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文