zoukankan      html  css  js  c++  java
  • Android学习笔记进阶十二之裁截图片

    1. package xiaosi.cut;  
    2. import java.io.File;  
    3. import android.app.Activity;  
    4. import android.content.Intent;  
    5. import android.graphics.drawable.Drawable;  
    6. import android.net.Uri;  
    7. import android.os.Bundle;  
    8. import android.view.View;  
    9. import android.view.View.OnClickListener;  
    10. import android.view.ViewGroup.LayoutParams;  
    11. import android.widget.Button;  
    12.   
    13. public class CutActivity extends Activity {  
    14.   
    15.     private static int SELECT_PICTURE;//返回标志位 filed  
    16.     private File tempFile;  
    17.     private Button button;  
    18.     /** Called when the activity is first created. */  
    19.     @Override  
    20.     public void onCreate(Bundle savedInstanceState) {  
    21.         super.onCreate(savedInstanceState);  
    22.         //setContentView(R.layout.main);  
    23.         this.tempFile = new File("/sdcard/song/a.jpg");  
    24.         button = new Button(this);  
    25.         button.setText("获取图片");  
    26.         button.setOnClickListener(new OnClickListener() {  
    27.             public void onClick(View v) {  
    28.                 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);  
    29.                 intent.setType("image/*");  
    30.                 intent.putExtra("crop", "true");// crop=true 有这句才能出来最后的裁剪页面.  
    31.   
    32.                 intent.putExtra("aspectX", 1);// 这两项为裁剪框的比例.  
    33.                 intent.putExtra("aspectY", 2);// x:y=1:2  
    34.   
    35.                 intent.putExtra("output", Uri.fromFile(tempFile));  
    36.                 intent.putExtra("outputFormat", "JPEG");//返回格式  
    37.   
    38.                 startActivityForResult(Intent.createChooser(intent, "选择图片"), SELECT_PICTURE);  
    39.             }  
    40.         });  
    41.         setContentView(button);  
    42.     }  
    43.   
    44.     /**  
    45.      * 裁剪完图片后系统调用的方法:onActivityResult  
    46.      */  
    47.     @Override  
    48.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
    49.         if (resultCode == RESULT_OK)  
    50.             if (requestCode == SELECT_PICTURE)  
    51.                 button.setBackgroundDrawable(Drawable.createFromPath(tempFile.getAbsolutePath()));  
    52.     }  
  • 相关阅读:
    散列
    Studio 3T破解方式
    springboot整合elasticsearch时的版本问题:
    ElasticSearch6.4.1 【Rejecting mapping update to [posts] as the final mapping would have more than 1 type】
    IP地址查询API
    拉姆达表达式 追加 条件判断 Expression<Func<T, bool>>
    类 映射 遍历大全
    jquery load(URL,FUNCTION(){}) 异步加载页面
    LINQ to Entities 不识别方法的解决方案
    当实体类属性超多时候 映射给实体类属性赋值(拉姆达+实体类映射)
  • 原文地址:https://www.cnblogs.com/Free-Thinker/p/6721794.html
Copyright © 2011-2022 走看看