代码拉取完成,页面将自动刷新
自定义相册,完全仿微信UI,实现了拍照、图片选择(单选/多选)、 裁剪 、旋转、等功能。
如果你发现有bug,或者好的建议,可以提merge request,我测试通过后会立即合并并发布新版本,确保该库处于可用的状态。
该项目参考了:
喜欢原作的可以去使用。同时欢迎大家下载体验本项目,如果使用过程中遇到什么问题,欢迎反馈。
使用前,对于DevEco Studio的用户,可以选择添加:
implementation "io.openharmony.tpc.thirdlib:ImagePicker:1.0.0"
配置参数 | 参数含义 |
---|---|
multiMode | 图片选着模式,单选/多选 |
selectLimit | 多选限制数量,默认为9 |
showCamera | 选择照片时是否显示拍照按钮 |
crop | 是否允许裁剪(单选有效) |
style | 有裁剪时,裁剪框是矩形还是圆形 |
focusWidth | 矩形裁剪框宽度(圆形自动取宽高最小值) |
focusHeight | 矩形裁剪框高度(圆形自动取宽高最小值) |
outPutX | 裁剪后需要保存的图片宽度 |
outPutY | 裁剪后需要保存的图片高度 |
isSaveRectangle | 裁剪后的图片是按矩形区域保存还是裁剪框的形状,例如圆形裁剪的时候,该参数给true,那么保存的图片是矩形区域,如果该参数给fale,保存的图片是圆形区域 |
imageLoader | 需要使用的图片加载器,自需要实现ImageLoader接口即可 |
更多使用,请下载demo参看源代码
com.lzy.imagepicker.loader.ImageLoader
这个接口,实现其中的方法,比如以下代码是使用 Picasso
三方加载库实现的public class PicassoImageLoader implements ImageLoader {
@Override
public void displayImage(Activity activity, String path, ImageView imageView, int width, int height) {
Picasso.with(activity)//
.load(Uri.fromFile(new File(path)))//
.placeholder(R.mipmap.default_image)//
.error(R.mipmap.default_image)//
.resize(width, height)//
.centerInside()//
.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)//
.into(imageView);
}
@Override
public void clearMemoryCache() {
//这里是清除缓存的方法,根据需要自己实现
}
}
AbilityPackage
初始化配置一次就可以,这里就需要将上面的图片加载器设置进来,其余的配置根据需要设置protected void onInitialize() {
super.onInitialize();
setContentView(R.layout.activity_image_picker);
ImagePicker imagePicker = ImagePicker.getInstance();
imagePicker.setImageLoader(new PicassoImageLoader()); //设置图片加载器
imagePicker.setShowCamera(true); //显示拍照按钮
imagePicker.setCrop(true); //允许裁剪(单选才有效)
imagePicker.setSaveRectangle(true); //是否按矩形区域保存
imagePicker.setSelectLimit(9); //选中数量限制
imagePicker.setStyle(CropImageView.Style.RECTANGLE); //裁剪框的形状
imagePicker.setFocusWidth(800); //裁剪框的宽度。单位像素(圆形自动取宽高最小值)
imagePicker.setFocusHeight(800); //裁剪框的高度。单位像素(圆形自动取宽高最小值)
imagePicker.setOutPutX(1000);//保存文件的宽度。单位像素
imagePicker.setOutPutY(1000);//保存文件的高度。单位像素
}
public void onClick(Component v) {
Intent intent = new Intent(this, ImageGridActivity.class);
startActivityForResult(intent, IMAGE_PICKER);
}
}
Intent intent = new Intent(this, ImageGridActivity.class);
intent.putExtra(ImageGridActivity.EXTRAS_TAKE_PICKERS,true); // 是否是直接打开相机
startActivityForResult(intent, REQUEST_CODE_SELECT);
onAbilityResult
方法,回调结果@Override
protected void onAbilityResult(int requestCode, int resultCode, Intent data) {
super.onAbilityResult(requestCode, resultCode, data);
if (resultCode == ImagePicker.RESULT_CODE_ITEMS) {
if (data != null && requestCode == IMAGE_PICKER) {
ArrayList<ImageItem> images = (ArrayList<ImageItem>) data.getSerializableExtra(ImagePicker.EXTRA_RESULT_ITEMS);
MyAdapter adapter = new MyAdapter(images);
gridView.setAdapter(adapter);
} else {
Toast.makeText(this, "没有数据", Toast.LENGTH_SHORT).show();
}
}
}
V 0.6.1
V 0.6.0
V 0.5.5
V 0.5.4
V 0.5.3
V 0.5.1
V 0.4.8
V 0.4.7
V 0.3.5
Copyright 2016 jeasonlzy(廖子尧)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。