激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|編程技術|正則表達式|

香港云服务器
服務器之家 - 編程語言 - JAVA教程 - 基于RxPaparazzo實現圖片裁剪、圖片旋轉、比例放大縮小功能

基于RxPaparazzo實現圖片裁剪、圖片旋轉、比例放大縮小功能

2020-09-29 13:50曦笑大海 JAVA教程

這篇文章主要為大家詳細介紹了基于RxPaparazzo實現圖片裁剪、圖片旋轉、比例放大縮小功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下

前言:基于RxPaparazzo的圖片裁剪圖片旋轉、比例放大|縮小。

效果:

 基于RxPaparazzo實現圖片裁剪、圖片旋轉、比例放大縮小功能

開發環境:AndroidStudio2.2.1+gradle-2.14.1 

涉及知識:

1.Material Design

(CardView+CoordinatorLayout+AppBarLayout+NestedScrollView+CollapsingToolbarLayout+Toolbar+FloatingActionButton)使用 

2.butterknife注解式開發 

3.基于RxJava+RxAndroid的RxPaparazzo使用 

引入依賴: 

?
1
2
3
4
5
6
7
8
9
10
11
12
compile 'com.android.support:appcompat-v7:24.+'
 //RxPaparazzo 拍照&相冊
// compile "com.github.miguelbcr:RxPaparazzo:0.4.2-2.x"
 compile ("com.github.miguelbcr:RxPaparazzo:0.5.2-2.x") {
 exclude module: 'okhttp'
 exclude module: 'okio'
 }
 compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
 compile 'com.android.support:cardview-v7:24.+'
// compile 'com.android.support:customtabs:24.+'
 compile 'com.android.support:design:24.+'
 compile 'com.jakewharton:butterknife:7.0.1'

部分代碼:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
public class MainActivity extends AppCompatActivity {
 
 @Bind(R.id.iv_appbar)
 ImageView iv_appbar;
 
 @Bind(R.id.main_toolbar)
 Toolbar toolbar;
 
 /* @Bind(R.id.btn_float)
 FloatingActionButton btn_float;*/
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 ButterKnife.bind(this);
 initToolBar();
 }
 
 private void initToolBar() {
 this.setSupportActionBar(toolbar);
 toolbar.setTitle("我的");
 }
 
 @OnClick({R.id.main_toolbar, R.id.btn_float})
 public void onClick(View view) {
 final UCrop.Options options = new UCrop.Options();
 int color = ContextCompat.getColor(view.getContext(), R.color.colorPrimary);
 options.setToolbarColor(color);
 options.setStatusBarColor(ContextCompat.getColor(view.getContext(), R.color.colorPrimaryDark));
 options.setActiveWidgetColor(color);
 switch (view.getId()) {
  case R.id.main_toolbar:
  Toast.makeText(MainActivity.this, "Toolbar點擊", Toast.LENGTH_SHORT).show();
  break;
  case R.id.btn_float: {
  showDialog(view, options);
  break;
  }
 }
 }
 
 private void showDialog(View view, final UCrop.Options options) {
 final Context context = view.getContext();
 final AlertDialog.Builder builder = new AlertDialog.Builder(context);
 builder.setTitle("設置背景圖片:").setMessage("如何獲取圖片?")
  .setPositiveButton("相冊", new DialogInterface.OnClickListener() {
   @Override
   public void onClick(DialogInterface dialog, int which) {
   dialog.dismiss();
//   RxPaparazzo.takeImage(MainActivity.this)
   RxPaparazzo.single(MainActivity.this)
    .crop(options)
    .usingGallery()
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(new Consumer<Response<MainActivity, FileData>>() {
     @Override
     public void accept(Response<MainActivity, FileData>
        response) throws Exception {
     if (response.resultCode() == Activity.RESULT_OK) {
 
      File filePath = response.data().getFile();
      Bitmap bitmap = BitmapFactory.
       decodeFile(filePath.getPath());
      iv_appbar.setImageBitmap(bitmap);
 
     } else if (response.resultCode() == Activity.RESULT_CANCELED) {
 
      Toast.makeText(MainActivity.this, "取消相冊訪問",
       Toast.LENGTH_SHORT).show();
 
     } else {
 
      Toast.makeText(MainActivity.this, "未知錯誤!",
       Toast.LENGTH_SHORT).show();
     }
     }
    });
   }
  })
  .setNeutralButton("取消", new DialogInterface.OnClickListener() {
   @Override
   public void onClick(DialogInterface dialog, int which) {
   dialog.dismiss();
   }
  })
  .setNegativeButton("拍照", new DialogInterface.OnClickListener() {
   @Override
   public void onClick(DialogInterface dialog, int which) {
   dialog.dismiss();
//   RxPaparazzo.takeImage(MainActivity.this)
   RxPaparazzo.single(MainActivity.this)
    .crop(options)
    .usingCamera()
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(new Consumer<Response<MainActivity, FileData>>() {
     @Override
     public void accept(Response<MainActivity, FileData>
        response) throws Exception {
 
     if (response.resultCode() == Activity.RESULT_OK) {
      FileData filePath = response.data();
      Bitmap bitmap = BitmapFactory.
       decodeFile(filePath.getFile().getPath());
      iv_appbar.setImageBitmap(bitmap);
     } else if (response.resultCode() == Activity.RESULT_CANCELED) {
      Toast.makeText(MainActivity.this, "取消拍照",
       Toast.LENGTH_SHORT).show();
     } else {
      Toast.makeText(MainActivity.this, "未知錯誤!",
       Toast.LENGTH_SHORT).show();
     }
     }
    });
   /**
    * new Consumer<Response<MainActivity, String>>() {
   @Override public void accept(@NonNull Response<MainActivity, String> response) throws Exception {
   if (response.resultCode() == Activity.RESULT_OK) {
   String filePath = response.data();
   Bitmap bitmap = BitmapFactory.decodeFile(filePath);
   iv_appbar.setImageBitmap(bitmap);
   } else if (response.resultCode() == Activity.RESULT_CANCELED) {
   Toast.makeText(MainActivity.this, "取消拍照", Toast.LENGTH_SHORT).show();
   } else {
   Toast.makeText(MainActivity.this, "未知錯誤!", Toast.LENGTH_SHORT).show();
   }
   }
   }
    *
    */
   }
  });
 
 AlertDialog dialog = builder.create();
 dialog.show();
 
 dialog.getButton(DialogInterface.BUTTON_POSITIVE).
 
  setTextColor(ContextCompat.getColor(context, R.color.colorPrimary)
  );
 dialog.getButton(DialogInterface.BUTTON_NEGATIVE).
 
  setTextColor(ContextCompat.getColor(context, R.color.colorPrimary)
 
  );
 dialog.getButton(DialogInterface.BUTTON_NEUTRAL).
 
  setTextColor(ContextCompat.getColor(context, R.color.colorAccent)
 
  );
 }
 
 @Override
 protected void onDestroy() {
 super.onDestroy();
 ButterKnife.unbind(this);//解除綁定
 }
}

源碼下載

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

延伸 · 閱讀

精彩推薦
575
主站蜘蛛池模板: 黑色丝袜美美女被躁视频 | 羞羞电影在线观看 | 中文字幕欧美视频 | 黄色片网站在线免费观看 | 全黄裸片武则天艳史 | 日本在线观看视频网站 | 成人国产免费观看 | 成年人视频在线免费观看 | 日本不卡一区二区在线观看 | 成人一级片毛片 | 日本韩国欧美一级片 | 色综合中文字幕 | 色婷婷a v| 99精品视频一区二区三区 | 蜜桃传媒视频麻豆第一区免费观看 | 亚洲国产视频网 | 国产一国产精品一级毛片 | hd性videos意大利复古 | 2019中文字幕在线播放 | 福利免费在线 | 九色 在线 | 欧美韩国一区 | 免费看日产一区二区三区 | 牛牛a级毛片在线播放 | 97青青草视频 | 日韩黄网站| 另类亚洲孕妇分娩网址 | 国产精品久久久久久久av三级 | 黄污网站在线 | 福利免费观看 | 免费毛片电影 | 男女羞羞视频在线免费观看 | 黄色片一区二区 | 久久草在线视频国产 | 久久久久999| 91精品国产日韩91久久久久久360 | 精品国产一区二区三区四区在线 | 91精品一区二区综合在线 | 欧美成人一区免费视频 | 精品久久久久久久久久中出 | 免费观看一区二区三区 |