• Android第三方开源图片裁剪截取:cropper


    

    Android第三方开源图片裁剪截取:cropper

    很多app都需要裁剪截取图片作为头像、logo之类,而cropper是github上的一个针对Android平台的、第三方开源图片裁剪截取项目,其项目主页是:https://github.com/edmodo/cropper

    cropper项目给出的一个例子以一张蝴蝶图作为目标图片进行裁剪截取,如图:


    cropper用法简单,给出一个例子,测试的MainActivity.java:

    package zhangphil.demo;
    
    import com.edmodo.cropper.CropImageView;
    
    import android.app.Activity;
    import android.graphics.Bitmap;
    import android.os.Bundle;
    import android.view.View;
    
    public class MainActivity extends Activity {
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    
    		final CropImageView cropImageView = (CropImageView) findViewById(R.id.CropImageView);
    
    		// 当触摸时候才显示网格线
    		cropImageView.setGuidelines(CropImageView.GUIDELINES_ON_TOUCH);
    
    		findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
    
    			@Override
    			public void onClick(View v) {
    				// 获取裁剪成的图片
    				Bitmap croppedImage = cropImageView.getCroppedImage();
    
    				cropImageView.setImageBitmap(croppedImage);
    			}
    		});
    	}
    }
    



    需要的布局文件:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context="zhangphil.demo.MainActivity" >
    
        <com.edmodo.cropper.CropImageView
            xmlns:custom="http://schemas.android.com/apk/res-auto"
            android:id="@+id/CropImageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:src="@drawable/girl" />
    
        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="裁剪" >
        </Button>
    
    </LinearLayout>


    附录文章:
    1,《Android设置头像,手机拍照或从本地相册选取图片作为头像》链接地址:http://blog.csdn.net/zhangphil/article/details/44829747

  • 相关阅读:
    个人收集
    30个提高Web程序执行效率的好经验
    如何进行有效的代码检查
    软件测试杂谈
    论dotnet应用程序通用开发方法的弊端
    给Linux增加硬盘的方法
    知识分子的生活态度
    深入认识敏捷开发和面向对象
    使用自定义主题让Windows Live Writer在本地预览语法高亮效果
    软件工程项目中数据库的作用以及敏捷开发
  • 原文地址:https://www.cnblogs.com/hehehaha/p/6147310.html
Copyright © 2020-2023  润新知