5 Star 1 Fork 1

HarmonyOS-TPC / SimpleCropView

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

SimpleCropView

SimpleCropView是适用于鸿蒙的图像裁剪库。它简化了裁剪图像的代码,并提供了易于自定义的UI。

概述

  • 支持普通裁剪和RxJava裁剪
  • 支持裁剪类型FIT_IMAGE、RATIO_4_3、RATIO_3_4、SQUARE、RATIO_16_9、RATIO_9_16、FREE、CIRCLE、 CIRCLE_SQUARE
  • 支持JPG格式图片裁剪后输出
  • 不支持裁剪后保存PNG格式图片
  • 不支持CUSTOM类型裁剪图片
  • 不支持setCompressQuality,setCompressFormat
  • 不支持scv_background_color和setBackgroundColor,请使用ViewGroup的背景色设置
  • 不支持roateImage旋转类型裁剪以及相应的动画设置

演示

集成

方式一:
通过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'

示例

Basic

         加载图片:
            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) {
                                }
                            });

Rxjava:

           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 Attributes

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.

License

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.
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.

简介

SimpleCropView是适用于鸿蒙的图像裁剪库。它简化了裁剪图像的代码,并提供了易于自定义的UI。 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/HarmonyOS-tpc/SimpleCropView.git
git@gitee.com:HarmonyOS-tpc/SimpleCropView.git
HarmonyOS-tpc
SimpleCropView
SimpleCropView
master

搜索帮助