Anyshape: An openharmony library that can help developers to display mask image in any shape.
This library - cn.lankton.anyshape, is very useful in the development of applications which are in our daily use. Some of such examples mentioned below:
|
|
In this section, we can see the list of features which the library provides which makes the use of this library very easy and friendly. Primarily, this library supports customization of component attributes using the below mechanism.
- Java APIs
Anyshape uses a simple fluent java API's that allows users to make most requests in a single line:
Features supported by this component includes the below:
-
Masking the any shape image using AnyShapeImageView:
ohos anyshape UI is displaying all different mask image will display. -
Masking the image in different color shape.:
ohos anyshape: while display the image ring color button ring will display different-2 kind of colors.
For using the library in your HarmonyOS mobile app, you need to first install it by following below methods.
- Method 1:
Generate the .har package through the library and add the .har package to the libs folder.Add the following code to the entry level build.gradle:implementation fileTree (dir: 'libs', include: ['* .jar', '* .har'])
- Method 2 :
Copy the dependency from the gitee and add it to the entry level build.gradle:
dependencies { implementation fileTree(dir: 'libs', include: ['*.har']) implementation 'io.openharmony.cn.lankton.anyshape.AnyshapeImageView:1.0.1' }
This section will help us to understand the usage of the library as you use it in your Harmony-application developemnt project.
We are going to load list into AnyshapeImageView component using This Library. So, add AnyshapeImageView component into resource_file.xml file.
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
xmlns:app="http://schemas.huawei.com/hap/res-auto"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:orientation="vertical"
ohos:background_element="#000000">
<cn.lankton.anyshape.AnyshapeImageView
ohos:id="$+id:iv_text"
ohos:width="match_content"
ohos:height="200vp"
ohos:scale_mode="center"
ohos:layout_alignment="center"
ohos:top_margin="-15vp"
/>
</DirectionalLayout>
@Override
public void onStart(Intent intent) {
super.onStart(intent);
PixelMap original = AnyshapeImageView.decodeResource(this, ResourceTable.Media_scene);
PixelMap mask = AnyshapeImageView.decodeResource(this, ResourceTable.Media_text);
PixelMap.InitializationOptions initializationOptions = new PixelMap.InitializationOptions();
initializationOptions.size = new Size(mask.getImageInfo().size.width, mask.getImageInfo().size.height);
initializationOptions.pixelFormat = PixelFormat.ARGB_8888;
PixelMap result = PixelMap.create(initializationOptions);
Texture texture = new Texture(result);
Canvas mCanvas = new Canvas(texture);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setBlendMode(BlendMode.DST_IN);
mCanvas.drawPixelMapHolder(new PixelMapHolder(original), 0, 0, new Paint());
mCanvas.drawPixelMapHolder(new PixelMapHolder(mask), 0,
}
Below is the list of XML attributes which are supported by the library.
Name | Type | Info |
---|---|---|
anyshapeBackColor | Color | To apply the color of the anyshapeview |
The public methods below will help us to operate on the component at runtime.
Anyshape Methods
|
In this section, we can have a look at some the examples where the APIs of this library is put to use and the results which we can acheive.
Example1: Anyshape with Change the Ring Color
Layout.xml:
<cn.lankton.anyshape.AnyshapeImageView ohos:id="$+id:iv_panda" ohos:height="250vp" ohos:width="250vp" ohos:layout_alignment="center" ohos:scale_mode="center" />Java Slice: PixelMap result = PixelMap.create(initializationOptions); Texture texture = new Texture(result); Canvas mCanvas = new Canvas(texture); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setBlendMode(BlendMode.DST_IN); mCanvas.drawPixelMapHolder(new PixelMapHolder(original), 0, 0, new Paint()); mCanvas.drawPixelMapHolder(new PixelMapHolder(mask), 0, 0, paint); iv_ring_image.setPixelMap(texture.getPixelMap()); |
Example2: Anyshape with apply Mask Element Panda
Layout.xml:
<cn.lankton.anyshape.AnyshapeImageView ohos:id="$+id:iv_panda" ohos:height="250vp" ohos:width="250vp" ohos:layout_alignment="center" ohos:scale_mode="center" />Java Slice: PixelMap result = PixelMap.create(initializationOptions); Texture texture = new Texture(result); Canvas mCanvas = new Canvas(texture); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setBlendMode(BlendMode.DST_IN); mCanvas.drawPixelMapHolder(new PixelMapHolder(original), 0, 0, new Paint()); 0, 0, paint); mCanvas.drawPixelMapHolder(new PixelMapHolder(mask), |
Example3: Anyshape with apply Text
Layout.xml:
<cn.lankton.anyshape.AnyshapeImageView ohos:id="$+id:iv_panda" ohos:height="250vp" ohos:width="250vp" ohos:layout_alignment="center" ohos:scale_mode="center" />Java Slice: PixelMap mask = AnyshapeImageView.decodeResource(this, ResourceTable.Media_personal); PixelMap.InitializationOptions initializationOptions = new PixelMap.InitializationOptions(); initializationOptions.size = new Size(mask.getImageInfo() .size.width, mask.getImageInfo().size.height); initializationOptions.pixelFormat = PixelFormat.ARGB_8888; PixelMap result = PixelMap.create(initializationOptions); Texture texture = new Texture(result); Canvas mCanvas = new Canvas(texture); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setBlendMode(BlendMode.DST_IN); mCanvas.drawPixelMapHolder(new PixelMapHolder(original), 0, 0, new Paint()); mCanvas.drawPixelMapHolder(new PixelMapHolder(mask), 0, 0, paint); iv_text_image.setPixelMap(texture.getPixelMap()); |
Anyshape is a very easy to use and very powerful library.The performance of the library is very good even when it works on one of the latest operating systems in the world, which is HarmonyOS!
-
For more exciting libraries to develop your app, peep into third-party-components at
OpenHarmony-TPC -
To know more about the developement work happening on harmony aaplication layer, and even be part of the exciting stuff, watch this space of Application Library Engineering Group