代码拉取完成,页面将自动刷新
SimpleCropView是适用于鸿蒙的图像裁剪库。它简化了裁剪图像的代码,并提供了易于自定义的UI。
方式一:
通过library生成har包,添加har包到libs文件夹内
在entry的gradle内添加如下代码
implementation fileTree(dir: 'libs', include: ['*.jar', '*.har'])
方式二:
allprojects{
repositories{
mavenCentral()
}
}
implementation 'io.openharmony.tpc.thirdlib:SimpleCropView-library:1.0.1'
加载图片:
cropImageView.load(uri).execute(new LoadCallback() {
@Override
public void onSuccess(PixelMap PixelMap) {
}
@Override
public void onError(Throwable e) {
}
});
裁剪:
cropImageView.crop(uri).execute(new CropCallback() {
@Override
public void onSuccess(PixelMap cropped) {
final String uriPath = "file://"+getContext().getFilesDir()+"/test33.jpg";
cropImageView.save(cropped)
.execute(Uri.parse(uriPath), new SaveCallback() {
@Override
public void onSuccess(Uri uri) {
LogUtil.error("test","裁剪保存成功:"+uri.toString());
}
@Override
public void onError(Throwable e) {
}
});
}
@Override
public void onError(Throwable e) {
}
});
String uriPath = "file://"+getContext().getFilesDir()+"/test22.jpg";
Observable<Integer> observable = Observable.create(emitter -> {
cropImageView.crop(uri)
.executeAsSingle()
.flatMap(new Function<PixelMap, SingleSource<Uri>>() {
@Override
public SingleSource<Uri> apply(@io.reactivex.annotations.NonNull PixelMap bitmap)
throws Exception {
cropImageView.getContext().getUITaskDispatcher().asyncDispatch(new Runnable() {
@Override
public void run() {
image1.setPixelMap(bitmap);
image1.setVisibility(Component.VISIBLE);
cropImageView.setVisibility(Component.INVISIBLE);
}
});
return cropImageView.save(bitmap)
.executeAsSingle(Uri.parse(uriPath));
}
})
.doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Disposable disposable)
throws Exception {
}
})
.doFinally(new Action() {
@Override
public void run() throws Exception {
}
})
.subscribeOn(Schedulers.newThread())
.subscribe(new Consumer<Uri>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Uri uri11) throws Exception {
File file = new File(uri11.getDecodedPath());
emitter.onComplete();
}
}, new Consumer<Throwable>() {
@Override
public void accept(@io.reactivex.annotations.NonNull Throwable throwable)
throws Exception {
emitter.onComplete();
}
});
});
observable.subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
}
});
XML sample here.
<DependentLayout
ohos:height="match_parent"
ohos:width="match_parent"
ohos:left_margin="24vp"
ohos:right_margin="24vp">
<com.isseiaoki.simplecropview.CropImageView
ohos:id="$+id:cropImageView"
ohos:height="400vp"
ohos:width="480vp"
ohos:center_in_parent="true"
custom:scv_crop_mode="circle"
custom:scv_frame_color="#5DAC81"
custom:scv_frame_stroke_weight="1vp"
custom:scv_guide_color="#5DAC81"
custom:scv_guide_show_mode="show_always"
custom:scv_guide_stroke_weight="1vp"
custom:scv_handle_color="#5DAC81"
custom:scv_handle_show_mode="show_always"
custom:scv_handle_size="14vp"
custom:scv_min_frame_size="50vp"
custom:scv_overlay_color="#AA1C1C1C"
custom:scv_touch_padding="8vp"
/>
</DependentLayout>
XML Attribute (custom:) |
Related Method | Description |
---|---|---|
scv_img_src | setImageResource(int resId) | Set source image. |
scv_crop_mode | setCropMode(CropImageView.CropMode mode) | Set crop mode. |
scv_overlay_color | setOverlayColor(int overlayColor) | Set image overlay color. |
scv_frame_color | setFrameColor(int frameColor) | Set the image cropping frame color. |
scv_handle_color | setHandleColor(int frameColor) | Set the handle color. |
scv_guide_color | setGuideColor(int frameColor) | Set the guide color. |
scv_guide_show_mode | setGuideShowMode(CropImageView.ShowMode mode) | Set guideline show mode. |
scv_handle_show_mode | setHandleShowMode(CropImageView.ShowMode mode) | Set handle show mode. |
scv_handle_size | setHandleSizeInDp(int handleDp) | Set handle radius in density-independent pixels. |
scv_touch_padding | setTouchPaddingInDp(int paddingDp) | Set the image cropping frame handle touch padding(touch area) in density-independent pixels. |
scv_min_frame_size | setMinFrameSizeInDp(int minDp) | Set the image cropping frame minimum size in density-independent pixels. |
scv_frame_stroke_weight | setFrameStrokeWeightInDp(int weightDp) | Set frame stroke weight in density-independent pixels. |
scv_guide_stroke_weight | setGuideStrokeWeightInDp(int weightDp) | Set guideline stroke weight in density-independent pixels. |
scv_crop_enabled | setCropEnabled(boolean enabled) | Set whether to show the image cropping frame. |
scv_initial_frame_scale | setInitialFrameScale(float initialScale) | Set Set initial scale of the frame.(0.01 ~ 1.0) |
scv_handle_shadow_enabled | setHandleShadowEnabled(boolean handleShadowEnabled) | Set whether to show handle shadows. |
The MIT License (MIT)
Copyright (c) 2015 Issei Aoki
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型