小编ADK*_*ADK的帖子

按多边形区域裁剪图像

我想通过多边形区域裁剪图像,但无法找到任何可以制作它的库.OpenCV对于这个小东西来说太大了.JJIL [ 在此输入链接描述 ]裁剪矩形区域.也许你有任何想法我怎么能实现它?感谢帮助!

在此输入图像描述 在此输入图像描述

对于Nidhi:尝试这样的东西,如果不起作用 - 为路径创建另一个画布,然后从中获取Bitmap(用于遮罩),并将此遮罩位图应用于初始画布而不是drawPath.

Bitmap obmp = BitmapFactory.decodeResource(getResources(), R.drawable.image1);
Bitmap resultImg = Bitmap.createBitmap(obmp.getWidth(), obmp.getHeight(), Bitmap.Config.ARGB_8888);
Bitmap maskImg = Bitmap.createBitmap(obmp.getWidth(), obmp.getHeight(), Bitmap.Config.ARGB_8888);

Canvas mCanvas = new Canvas(resultImg);
Canvas maskCanvas = new Canvas(maskImg);

Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.FILL);;
paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));

Path path = new Path();
path.moveTo(view.mx,view.my);
path.lineTo(view.x1,view.y1);
path.lineTo(view.x2,view.y2 );
path.lineTo(view.x3,view.y3);
path.lineTo(view.x4,view.y4);
path.close();

maskCanvas.drawPath(path, paint);   
mCanvas.drawBitmap(obmp, 0, 0, null);
mCanvas.drawBitmap(maskImg, 0, 0, paint);
Run Code Online (Sandbox Code Playgroud)

android image crop image-processing

6
推荐指数
1
解决办法
8441
查看次数

我如何使RelativeLayout适合屏幕?

我正面临屏幕外的问题按钮显示RelativeLayout.ImageView不会缩放图片以给出按钮可见的位置.

是)我有的:

在此输入图像描述

我想要的是:

在此输入图像描述

码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:gravity="center_vertical"  >

<TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/str"
        android:textAppearance="@android:style/TextAppearance.Small"
        android:textColor="?android:attr/textColorTertiary"
        android:layout_centerHorizontal="true"
        />

<ru.mw.widget.DrawableImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView"
        android:adjustViewBounds="true"
        android:layout_centerHorizontal="true"
        android:scaleType="centerCrop"
        />

<Button
        android:id="@+id/processButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/str"
        android:layout_below="@+id/imageView"
        android:layout_centerHorizontal="true"
        />
Run Code Online (Sandbox Code Playgroud)

当我改变屏幕方向时出现问题:如果我在横向模式下使用Arun C Thomas的方法一切正常,但在纵向模式下我有这个(图像被左/右边缘裁剪):

在此输入图像描述 预期结果:

在此输入图像描述

xml android relativelayout android-layout

5
推荐指数
1
解决办法
2600
查看次数

如何以编程方式为LinearLayout指定layout_below?

我想以编程方式执行此类操作 -

<RelativeLayout1>
  <LinearLayout name = 1>
  <LinearLayout below = 1>
<RelativeLayout1>
Run Code Online (Sandbox Code Playgroud)

我试着这样做:

LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)mButtonContainer.getLayoutParams();
Run Code Online (Sandbox Code Playgroud)

params有weight田野,width田野,但没有layout_below...感谢您的帮助!

android android-layout

3
推荐指数
1
解决办法
1万
查看次数