iink SDK on Device

When using the recognizer on SDK version 4.2, use an eraser to erase some strokes

When using a recognizer, how to identify the erased part? For example, if I write ABCD and then erase the area where B is located, how do I tell the recognizer that I have erased a part




Hello,


Thank you for contacting us.


The Recognizers aim at performing real-time incremental recognition on transient ink. It means that you can't edit your ink with the Text Recognizer to erase ink strokes, for instance.


When you indicate erase the area where B is located, do you mean to erase corresponding ink or the corresponding typeset in your application?

Depending on what you want to achieve, we can guide you to the use of the best suited object: Recognizer, Editor or OffScreenEditor.


Gwenaëlle

hello:

Erase the handwriting drawn on my custom view, and simultaneously inform the recognizer that this area is empty. This is the function I want to achieve.

For example, I wrote ABCD on the view. Then I erased B using an eraser. What processing can I do to make the recognizer tell me that the current recognized content is ACD.


Thank you for the update!

The Recognizer does not handle an ink model because it considers that ink is transient: Once ink has been sent to the Recognizer, it cannot be edited anymore, so it can't be erased.
Therefore, the Recognizer object is not suited to your use case.
Since you want to interact with your ink, you must use a different object, either an Editor or an OffscreenEditor:
https://developer.myscript.com/docs/interactive-ink/4.3/concepts/interactive-ink/

If you want to use your own ink rendering, you must use an OffscreenEditor.
You can refer to the OffscreenEditor section of the documentation https://developer.myscript.com/docs/interactive-ink/4.3/android/advanced/off-screen-usage/
and to our offscreen interactivity Android sample that illustartes such a use case https://github.com/MyScript/interactive-ink-additional-examples-android/tree/master

If you use iink SDK rendering, you must use an Editor object see https://developer.myscript.com/docs/interactive-ink/4.3/android/fundamentals/rendering/
Our iink SDK Demo example relies on an Editor object.


Best regards,


Gwenaëlle


hello 

This is my code:

                displayMetrics=activity.getResources().getDisplayMetrics();
Log.d(TAG, "onViewInited: xdpi-ydpi->"+displayMetrics.xdpi+"-"+displayMetrics.ydpi);
// 1️⃣ 创建 OffscreenEditor
OffscreenEditor offscreenEditor = engine.createOffscreenEditor(
displayMetrics.xdpi,
displayMetrics.ydpi
);
mView.setOffscreenEditor(offscreenEditor);
ContentPackage contentPackage;
ContentPart contentPart;
try {
File iinkFile = new File(
activity.getFilesDir(),
"handwrite.iink"
);

contentPackage = engine.createPackage(iinkFile);
contentPart = contentPackage.createPart("Raw Content");
offscreenEditor.setPart(contentPart);

} catch (Exception e) {
Log.e(TAG, "create iink package failed", e);
}

offscreenEditor.addListener(new IOffscreenEditorListener() {
@Override
public void partChanged(@NotNull OffscreenEditor offscreenEditor) {

}

@Override
public void contentChanged(@NotNull OffscreenEditor offscreenEditor, @NonNull @NotNull String[] strings) {
try {
String jiix = offscreenEditor.export_(
new String[0],
MimeType.JIIX
);
Log.d(TAG, "JIIX RESULT = " + jiix);

//

This is result,don't hava   lable  content 

JIIX RESULT = {

                                                                                                     "type": "Raw Content",

                                                                                                     "bounding-box": {

                                                                                                      "x": 145017.547,

                                                                                                      "y": 103932.797,

                                                                                                      "width": 48690.2656,

                                                                                                      "height": 166473.703

                                                                                                     },

                                                                                                     "elements": [ {

                                                                                                       "type": "Raw Content",

                                                                                                       "kind": "text",

                                                                                                       "id": "raw-content/11",

                                                                                                       "bounding-box": {

                                                                                                        "x": 145017.547,

                                                                                                        "y": 103932.797,

                                                                                                        "width": 48690.2656,

                                                                                                        "height": 166473.703

                                                                                                       },

                                                                                                       "items": [ {

                                                                                                         "timestamp": "2026-01-15 13:50:26.529000",

                                                                                                         "X": [ 152145.141, 152145.141, 152205.797, 152266.438, 152327.094, 152372.578, 152372.578, 152357.422,

                                                                                                          152296.766, 152190.625, 152039, 151841.875, 151614.438, 151356.656, 151068.562, 150750.141,

                                                                                                          150401.406, 150022.312, 149643.25, 149249.016, 148885.109, 148566.672, 148293.75, 148096.625,

                                                                                                          147975.328, 147929.828, 147945, 148005.641, 148081.469, 148172.438, 148278.578, 148384.719,

                                                                                                          148506.031, 148581.844, 148612.172 ],

                                                                                                         "Y": [ 108963.633, 108963.633, 108801.375, 108639.109, 108503.914, 108449.828, 108449.828, 108585.062,

                                                                                                          108909.547, 109558.555, 110532.086, 111803.078, 113344.461, 115102.203, 117103.352, 119374.898,

                                                                                                          121808.664, 124377.672, 126892.594, 129245.289, 131408.656, 133409.766, 135167.5, 136681.875,

                                                                                                          137898.766, 138791.156, 139440.203, 139872.859, 140089.203, 140089.203, 139791.75, 139088.656,

                                                                                                          138061.031, 136735.953, 135275.688 ],

                                                                                                         "F": [ 1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1 ],

                                                                                                         "T": [ 0, 4, 4, 4, 5, 5, 5, 5,

                                                                                                          5, 5, 5, 5, 6, 6, 6, 6,

                                                                                                          6, 7, 7, 7, 7, 7, 7, 7,

                                                                                                          8, 8, 8, 8, 8, 8, 8, 8,

                                                                                                          9, 9, 9 ],

                                                                                                         "type": "stroke",

                                                                                                         "id": "0000000001004500ff00"

                                                                                                        }, {

                                                                                                         "timestamp": "2026-01-15 13:50:26.849000",

                                                                                                         "X": [ 154343.766, 154343.766, 154358.938, 154389.25, 154465.062, 154556.047, 154677.344, 154798.656,

                                                                                                          154950.281, 155101.906, 155299.031, 155496.156, 155723.594, 155951.047, 156193.656, 156421.094,

                                                                                                          156648.547, 156860.828, 157057.938, 157239.891, 157406.688, 157573.469, 157725.094, 157861.578,

                                                                                                          157982.875, 158073.859, 158119.344, 158119.344, 158089.016, 157998.031, 157831.25, 157573.469,

                                                                                                          157239.891, 156785, 156223.969 ],

                                                                                                         "Y": [ 103933.797, 103933.797, 104609.828, 105556.336, 106854.352, 108449.828, 110288.711, 112235.734,

                                                                                                          114209.82, 116346.164, 118644.734, 121105.57, 123674.578, 126216.555, 128596.281, 130840.766,

                                                                                                          132923.016, 134788.938, 136465.562, 137871.75, 139007.5, 139953.969, 140657.062, 141224.969,

                                                                                                          141603.578, 141819.875, 141928.062, 141928.062, 141765.797, 141441.312, 140954.562, 140224.406,

                                                                                                          139250.875, 138061.031, 136735.953 ],

                                                                                                         "F": [ 1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1 ],

                                                                                                         "T": [ 0, 15, 16, 16, 16, 16, 16, 16,

                                                                                                          16, 16, 17, 17, 17, 17, 17, 17,

                                                                                                          17, 17, 17, 19, 19, 19, 20, 20,

                                                                                                          20, 20, 20, 20, 20, 20, 21, 21,

                                                                                                          21, 21, 21 ],

                                                                                                         "type": "stroke",

                                                                                                         "id": "0000010001004500ff00"

                                                                                                        }, {

                                                                                                         "timestamp": "2026-01-15 13:50:27.063000",

                                                                                                         "X": [ 148263.422, 148263.422, 148460.531, 148794.125, 149203.516, 149734.234, 150386.234, 151114.047,

                                                                                                          151902.531, 152645.516, 153297.531, 153828.219, 154252.781, 154586.375, 154844.141, 155026.094,

                                                                                                          155147.406, 155223.219, 155283.875, 155299.031, 155299.031, 155253.547, 155192.891, 155101.906,

                                                                                                          154965.453 ],

                                                                                                         "Y": [ 127406.398, 127406.398, 127487.547, 127595.727, 127730.922, 127839.094, 127893.18, 127893.18,

                                                                                                          127893.18, 127839.094, 127839.094, 127839.094, 127839.094, 127812.031, 127785.008, 127757.945,

                                                                                                          127703.859, 127649.773, 127595.727, 127487.547, 127325.289, 127163.023, 126946.68, 126757.391,

                                                                                                          126568.102 ],

                                                                                                         "F": [ 1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1 ],

                                                                                                         "T": [ 0, 2, 2, 2, 3, 3, 4, 4,

                                                                                                          4, 4, 5, 8, 9, 9, 10, 10,

                                                                                                          10, 10, 10, 10, 10, 11, 11, 11,

                                                                                                          11 ],

                                                                                                         "type": "stroke",

                                                                                                         "id": "0000020001003100ff00"

                                                                                                        }, {

2026-01-15 19:22:29.176 2502-2668 NoteView com.lxzx.app D "timestamp": "2026-01-15 13:50:27.673000",

                                                                                                         "X": [ 145018.547, 145018.547, 145064.031, 145139.859, 145245.984, 145397.625, 145594.75, 145807.031,

                                                                                                          146034.453, 146277.062, 146519.672, 146747.125, 146944.234, 147126.188, 147247.5, 147323.312,

                                                                                                          147338.469, 147308.156, 147247.5, 147141.359, 147050.391, 146944.234, 146868.422, 146822.938,

                                                                                                          146807.781, 146822.938, 146868.422, 146913.906, 146974.562, 147035.219, 147065.547, 147050.391,

                                                                                                          146974.562 ],

                                                                                                         "Y": [ 236602.797, 236602.797, 236440.531, 236359.391, 236305.328, 236359.391, 236494.625, 236792.078,

                                                                                                          237305.891, 238036.016, 239063.625, 240496.844, 242335.734, 244553.188, 247095.172, 249718.266,

                                                                                                          252395.406, 255072.594, 257614.562, 260048.359, 262265.812, 264185.812, 265835.406, 267187.5,

                                                                                                          268242.156, 269053.406, 269621.312, 270026.938, 270270.312, 270405.5, 270270.312, 269891.719,

                                                                                                          269215.656 ],

                                                                                                         "F": [ 1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1 ],

                                                                                                         "T": [ 0, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          2, 2, 2, 2, 2, 2, 3, 3,

                                                                                                          3, 3, 3, 3, 3, 4, 4, 4,

                                                                                                          5, 6, 6, 6, 6, 6, 7, 7,

                                                                                                          7 ],

                                                                                                         "type": "stroke",

                                                                                                         "id": "0000030001004100ff00"

                                                                                                        }, {

                                                                                                         "timestamp": "2026-01-15 13:50:28.169000",

                                                                                                         "X": [ 148172.438, 148172.438, 148324.078, 148839.609, 149203.516, 149612.922, 150052.641, 150522.703,

                                                                                                          151023.078, 151538.609, 152039, 152493.891, 152842.641, 153100.406, 153221.703, 153206.547,

                                                                                                          153009.422, 152645.516, 152114.812, 151462.797, 150780.469, 150082.969, 149415.797, 148778.953,

                                                                                                          148217.938, 147717.547, 147323.312, 147035.219, 146822.938, 146701.625, 146671.297, 146731.953,

                                                                                                          146868.422, 147111.031, 147474.953, 147945, 148536.344, 149233.844, 150067.812, 151038.25,

                                                                                                          152069.328, 153085.25, 153995.016, 154798.656, 155450.656, 155966.203, 156330.109, 156527.234,

                                                                                                          156557.562, 156451.422, 156208.812, 155829.734, 155329.359, 154722.844, 153979.844, 153176.219,

                                                                                                          152342.25, 151538.609, 150795.641, 150082.969, 149355.156, 148566.672 ],

                                                                                                         "Y": [ 230166.734, 230166.734, 230220.812, 230572.359, 230815.734, 231113.234, 231410.703, 231708.156,

                                                                                                          232059.703, 232411.25, 232789.828, 233168.438, 233547, 233952.641, 234466.453, 235088.438,

                                                                                                          235845.609, 236738, 237711.531, 238685.016, 239685.578, 240686.172, 241713.75, 242768.391,

                                                                                                          243768.984, 244742.469, 245553.75, 246229.812, 246770.641, 247230.375, 247608.938, 247906.406,

                                                                                                          248149.812, 248312.031, 248366.125, 248339.094, 248230.922, 248149.812, 248095.719, 248122.75,

                                                                                                          248312.031, 248582.469, 248988.109, 249501.922, 250096.828, 250772.906, 251503.031, 252287.266,

                                                                                                          253152.594, 254072.031, 255099.656, 256181.312, 257398.219, 258750.344, 260156.531, 261562.719,

                                                                                                          262833.719, 263969.5, 264997.094, 265862.438, 266538.5, 266971.156 ],

                                                                                                         "F": [ 1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1, 1, 1,

                                                                                                          1, 1, 1, 1, 1, 1 ],

                                                                                                         "T": [ 0, 3, 3, 4, 4, 4, 4, 4,

                                                                                                          4, 4, 5, 5, 5, 5, 5, 5,

                                                                                                          5, 5, 5, 6, 6, 6, 6, 6,

                                                                                                          6, 6, 6, 6, 7, 7, 7, 8,

                                                                                                          8, 8, 8, 8, 8, 9, 9, 9,

                                                                                                          9, 9, 9, 9, 9, 10, 10, 10,

                                                                                                          10, 10, 10, 10, 10, 11, 11, 11,

                                                                                                          11, 11, 11, 11, 11, 11 ],

                                                                                                         "type": "stroke",

                                                                                                         "id": "0000040001007b00ff00"

                                                                                                        }, {

                                                                                                         "timestamp": "2026-01-15 13:52:27.868000",

                                                                                                         "X": [ 189218.562, 189218.562, 189188.234, 189142.766, 189082.109, 189006.297, 188884.984, 188718.188,

                                                                                                          188475.594, 188126.844, 187671.953, 187080.594, 186383.109, 185640.109, 184866.797, 184154.141,

                                                                                                          183532.453, 182986.609, 182516.531, 182167.797, 181940.359, 181864.531, 181925.188, 182137.469,

                                                                                                          182516.531, 183062.406, 183790.234, 184700.016, 185746.25, 186838, 187869.062, 188763.672,

                                                                                                          189521.844, 190113.188, 190537.75, 190810.688, 190962.328, 191022.953 ],

2026-01-15 19:22:29.176 2502-2668 NoteView com.lxzx.app D "Y": [ 110910.656, 110910.656, 110613.195, 110396.883, 110207.562, 110099.422, 110045.336, 110153.477,

                                                                                                          110450.969, 110991.805, 111830.102, 112911.805, 114155.734, 115534.898, 117103.352, 118888.109,

                                                                                                          120835.172, 122890.367, 124945.57, 126838.539, 128596.281, 130083.578, 131327.547, 132301.031,

                                                                                             

Thank you for your update and sharing code snippets.

It seems that you are using default values for most configuration properties for your Engine/OffscreenEditor.
In this case, the iink SDK Engine classifies the ink strokes as "text" or "drawing" strokes, but no recognition is run, so there is no text recognition label in the jiix export. See https://developer.myscript.com/docs/interactive-ink/4.3/reference/configuration/#raw-content

Raw Content parts are highly flexible, so you must define the right configuration values according to your needs:
See https://developer.myscript.com/docs/interactive-ink/4.3/overview/content-types/#raw-content-highlights

You can also refer to the offscreen-interactivity example for which we have defined a .json file providing a ready to use configuration file, that is a good starting point that you can customize:
https://github.com/MyScript/interactive-ink-additional-examples-android/blob/master/samples/offscreen-interactivity/src/main/assets/part_conf.json

This file can then be injected to your OffScreenEditor configuration as described in the doc
https://developer.myscript.com/docs/interactive-ink/4.3/android/fundamentals/interactive-ink-runtime/#editor-level-configuration
In the offscreen-interactivity example, it corresponds to this code section https://github.com/MyScript/interactive-ink-additional-examples-android/blob/addef104bc81ed8f23c502166925109a318149f9/samples/offscreen-interactivity/src/main/java/com/myscript/iink/demo/inksample/ui/InkViewModel.kt#L450


Best regards,


Gwenaëlle



Can you provide a case study based on Java? Kotlin is beyond my technical capability


hello: 

在我使用橡皮擦的时候代码是这样写的

List<PointerEvent> buffer = new ArrayList<>()
buffer.add(new PointerEvent(PointerEventType.DOWN,x,y,SystemClock.uptimeMillis(),event.getPressure(),PointerType.ERASER,1));
buffer.add(new PointerEvent(PointerEventType.MOVE,x,y,SystemClock.uptimeMillis(),event.getPressure(),PointerType.ERASER,1));
buffer.add(new PointerEvent(PointerEventType.UP,x,y,SystemClock.uptimeMillis(),event.getPressure(),PointerType.ERASER,1));
PointerEvent[] events = buffer.toArray(new PointerEvent[0]);
offscreenEditor.addStrokes(events, true );

SDK was actually recognized that I drew an extra line, rather than using an eraser.

please help me



Hello,


When using the OffscreenEditor your application is responsible of the ink model, for this reason, even if OffscreenEditor addStrokes accepts any PointerEvents.PointerType , events are always processed as PEN.

If you want to erase some strokes, you must use the OffscreenEditor erase method for erasing full strokes, for instance:

    
    // Add stroke, do not process gesture recognition
    String[] strokeIds = editor.addStrokes(pointerEvents, false);

    // Wait for text recognition processing
    editor.waitForIdle();

    // Erase stroke
     editor.erase(strokeIds);



If you want to erase partial strokes, you must use the replaceStrokes method:


Parameters:
itemIds - the item ids to replace. Unknown ids are ignored.
events - the replacing strokes pointer events (with coordinates in input units).


 Best regards,


Gwenaëlle

Login or Signup to post a comment