{"id":23898064,"url":"https://github.com/byteszero/cutpicdemo-for-android","last_synced_at":"2025-04-10T17:05:14.685Z","repository":{"id":26877878,"uuid":"30338468","full_name":"BytesZero/cutPicDemo-for-Android","owner":"BytesZero","description":"Android剪切图片的Demo","archived":false,"fork":false,"pushed_at":"2015-04-04T15:23:38.000Z","size":293,"stargazers_count":12,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T14:46:16.766Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BytesZero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-05T04:56:13.000Z","updated_at":"2023-02-24T12:16:50.000Z","dependencies_parsed_at":"2022-06-26T23:33:00.906Z","dependency_job_id":null,"html_url":"https://github.com/BytesZero/cutPicDemo-for-Android","commit_stats":null,"previous_names":["byteszero/cutpicdemo-for-android"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BytesZero%2FcutPicDemo-for-Android","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BytesZero%2FcutPicDemo-for-Android/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BytesZero%2FcutPicDemo-for-Android/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BytesZero%2FcutPicDemo-for-Android/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BytesZero","download_url":"https://codeload.github.com/BytesZero/cutPicDemo-for-Android/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248260176,"owners_count":21074207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-04T17:19:49.252Z","updated_at":"2025-04-10T17:05:14.653Z","avatar_url":"https://github.com/BytesZero.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cutPicDemo\nAndroid剪切图片的Demo\n###Demo的图片\n![](https://github.com/yy1300326388/cutPicDemo/blob/master/pic/device-2015-02-05-125204.png) \n![](https://github.com/yy1300326388/cutPicDemo/blob/master/pic/device-2015-02-05-125326.png) \n###实现代码\n``` java\npublic class MainActivity extends ActionBarActivity {\n\n    public static final int NONE = 0;\n    public static final int PHOTOHRAPH = 1;// 拍照\n    public static final int PHOTOZOOM = 2; // 缩放\n    public static final int PHOTORESOULT = 3;// 结果\n\n    public static final String IMAGE_UNSPECIFIED = \"image/*\";\n    ImageView imageView = null;\n    Button button0 = null;\n    Button button1 = null;\n\n    @Override\n    public void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        setContentView(R.layout.activity_main);\n        imageView = (ImageView) findViewById(R.id.imageID);\n        button0 = (Button) findViewById(R.id.btn_01);\n        button1 = (Button) findViewById(R.id.btn_02);\n\n        button0.setOnClickListener(new View.OnClickListener(){\n            @Override\n            public void onClick(View v) {\n                Intent intent = new Intent(Intent.ACTION_PICK, null);\n                intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, IMAGE_UNSPECIFIED);\n                startActivityForResult(intent, PHOTOZOOM);\n            }\n        });\n\n        button1.setOnClickListener(new View.OnClickListener() {\n\n            @Override\n            public void onClick(View v) {\n                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);\n                intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), \"temp.jpg\")));\n                startActivityForResult(intent, PHOTOHRAPH);\n            }\n        });\n    }\n\n    @Override\n    protected void onActivityResult(int requestCode, int resultCode, Intent data) {\n        if (resultCode == NONE)\n            return;\n        // 拍照\n        if (requestCode == PHOTOHRAPH) {\n            //设置文件保存路径这里放在跟目录下\n            File picture = new File(Environment.getExternalStorageDirectory() + \"/temp.jpg\");\n            startPhotoZoom(Uri.fromFile(picture));\n        }\n\n        if (data == null)\n            return;\n\n        // 读取相册缩放图片\n        if (requestCode == PHOTOZOOM) {\n            startPhotoZoom(data.getData());\n        }\n        // 处理结果\n        if (requestCode == PHOTORESOULT) {\n            Bundle extras = data.getExtras();\n            if (extras != null) {\n                Bitmap photo = extras.getParcelable(\"data\");\n                ByteArrayOutputStream stream = new ByteArrayOutputStream();\n                photo.compress(Bitmap.CompressFormat.JPEG, 75, stream);// (0 - 100)压缩文件\n                imageView.setImageBitmap(photo);\n            }\n\n        }\n\n        super.onActivityResult(requestCode, resultCode, data);\n    }\n\n    public void startPhotoZoom(Uri uri) {\n        Intent intent = new Intent(\"com.android.camera.action.CROP\");\n        intent.setDataAndType(uri, IMAGE_UNSPECIFIED);\n        intent.putExtra(\"crop\", \"true\");\n        // aspectX aspectY 是宽高的比例\n        intent.putExtra(\"aspectX\", 1);\n        intent.putExtra(\"aspectY\", 1);\n        // outputX outputY 是裁剪图片宽高\n        intent.putExtra(\"outputX\", 100);\n        intent.putExtra(\"outputY\", 100);\n        intent.putExtra(\"return-data\", true);\n        startActivityForResult(intent, PHOTORESOULT);\n    }\n}\n``` \n```java\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cLinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    android:orientation=\"vertical\"\n    android:layout_width=\"fill_parent\"\n    android:layout_height=\"fill_parent\"\u003e\n\n    \u003cTextView\n        android:layout_width=\"fill_parent\"\n        android:layout_height=\"wrap_content\"\n        android:text=\"imgDemo\" /\u003e\n    \u003cButton\n        android:id=\"@+id/btn_01\"\n        android:layout_height=\"50dip\"\n        android:text=\"相册\"\n        android:layout_width=\"match_parent\" /\u003e\n\n    \u003cButton\n        android:id=\"@+id/btn_02\"\n        android:layout_height=\"50dip\"\n        android:text=\"拍照\"\n        android:layout_width=\"match_parent\" /\u003e\n\n    \u003cImageView\n        android:id=\"@+id/imageID\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\" /\u003e\n\n\n\u003c/LinearLayout\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyteszero%2Fcutpicdemo-for-android","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbyteszero%2Fcutpicdemo-for-android","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyteszero%2Fcutpicdemo-for-android/lists"}