Android从相册选择一个图片、剪切、上传

1、从Android系统相册选择一张图片getImageFromAlbum():

    /**
     * 从图库获得照片
     */
    protected void getImageFromAlbum() {
        isImgs = true;
        // MainApplication.changeSettingStateus = true;
        Intent intent = new Intent(Intent.ACTION_PICK);
        intent.setType("image/*");// 相片类型
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("outputX", 360);
        intent.putExtra("outputY", 360);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", true);
        // intent.putExtra("outputFormat",
        // Bitmap.CompressFormat.JPEG.toString());
        intent.putExtra("noFaceDetection", true); // no face detection
        startActivityForResult
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android中,可以通过自定义View的方式来实现图片剪切圆角的效果。以下是一个简单的示例代码: 1. 自定义一个RoundImageView类,继承自ImageView: ``` public class RoundImageView extends ImageView { private Paint mPaint; private RectF mRectF; private float mRadius; public RoundImageView(Context context) { this(context, null); } public RoundImageView(Context context, AttributeSet attrs) { this(context, attrs, 0); } public RoundImageView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mPaint = new Paint(); mRectF = new RectF(); mPaint.setAntiAlias(true); } @Override protected void onDraw(Canvas canvas) { Drawable drawable = getDrawable(); if (drawable == null) { super.onDraw(canvas); return; } if (getWidth() == 0 || getHeight() == 0) { return; } Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap(); Bitmap roundBitmap = getRoundBitmap(bitmap, getWidth(), getHeight(), mRadius); mPaint.reset(); canvas.drawBitmap(roundBitmap, 0, 0, mPaint); } private Bitmap getRoundBitmap(Bitmap bitmap, int width, int height, float radius) { Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(output); mRectF.set(0, 0, width, height); canvas.drawRoundRect(mRectF, radius, radius, mPaint); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(bitmap, null, mRectF, mPaint); return output; } public void setRadius(float radius) { this.mRadius = radius; invalidate(); } } ``` 2. 在xml布局文件中引用这个RoundImageView: ``` <com.example.RoundImageView android:id="@+id/iv_round" android:layout_width="100dp" android:layout_height="100dp" android:scaleType="centerCrop" android:src="@drawable/test" app:radius="20dp"/> ``` 3. 在Activity中找到这个RoundImageView,并调用setRadius()方法设置圆角半径: ``` RoundImageView roundImageView = findViewById(R.id.iv_round); roundImageView.setRadius(20); ``` 这样就可以实现在Android中对图片进行圆角剪切的效果了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值