Android开发Easy Image 使用总结

释放双眼,带上耳机,听听看~!

添加依赖如上所示 并添加网络权限

package com.example.administrator.uploadimg;
import android.app.Activity;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import java.io.File;
import pl.aprilapps.easyphotopicker.EasyImage;
import pl.tajchert.nammu.Nammu;
public class MainActivity extends Activity{
private Button btn1;
private Button btn2;
private ImageView imgview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EasyImage.configuration(this)
.setImagesFolderName("My app images")
.saveInRootPicturesDirectory();
btn1 = (Button) findViewById(R.id.tackpic);
btn2 = (Button) findViewById(R.id.egtkpic);
imgview = (ImageView) findViewById(R.id.imgview);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
EasyImage.openCamera(MainActivity.this);
} catch (Exception e) {
e.printStackTrace();
Log.i("没有权限","没有权限");
}
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//                Intent intent=new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "10086"));
//                startActivity(intent);
//相册 或者 文件管 理器
//                EasyImage.openDocuments(MainActivity.this);
// 相册
//                EasyImage.openGallery(MainActivity.this);
//                EasyImage.openChooser(MainActivity.this,"xxxx");
//这里的dddd是弹出框的文本信息,例如拍照图库选择
EasyImage.openChooser(MainActivity.this,"dddddd", true);
//  EasyImage.openDocuments(Activity activity, int type);  int type  可以写成0
}
});
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
Nammu.onRequestPermissionsResult(requestCode, permissions, grantResults);
//        Nammu.getPrevPermissions();
Nammu.getPreviousPermissions();
Nammu.getGrantedPermissions();
Log.i("拍照","没权限");
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
EasyImage.handleActivityResult(requestCode, resultCode, data, this, new EasyImage.Callbacks() {
@Override
public void onImagePickerError(Exception e, EasyImage.ImageSource source) {
//Some error handlin
}
@Override
public void onImagePicked(File imageFile, EasyImage.ImageSource source) {
//Handle the image
//                String ss= imageFile.getAbsolutePath();
//得到路径
String ss=imageFile.getPath();
//               onPhotoReturned(imageFile);
Log.i("路径", ss);
//                imgview.setImageBitmap(source);
imgview.setImageBitmap(BitmapFactory.decodeFile(ss));
//                BitmapFactory.decodeFile(ss).recycle();
}
@Override
public void onCanceled(EasyImage.ImageSource imageSource) {
//                onPhotoReturned(imageFile);
}
});
}
}

 

<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=".MainActivity">
<Button
android:id="@+id/tackpic"
android:text="拍照"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/egtkpic"
android:text="选择相册"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/imgview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

demo

 

 

 

人已赞赏
Android文章

Android ViewPager使用详解

2020-3-28 13:03:31

Android文章

Android StartActivityForResult

2020-3-28 15:01:55

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索