AIWROK精准裁剪功能:按坐标和百分比操作
<p></p><div><br></div><div><table cellspacing="0" cellpadding="0" style="table-layout: fixed; width: 979px;"><tbody><tr><td class="t_f" id="postmessage_315" style="line-height: 24px;"><div data-v-77845de8="" id="content-side" style="box-shadow: rgba(0, 0, 0, 0.1) 0px 0px 4px; border-bottom: 1px solid rgba(0, 0, 0, 0.05); min-width: 830px; max-width: 850px; border-radius: 8px; margin-left: 10px; margin-right: 10px; color: rgb(52, 58, 64); font-family: "Microsoft Yahei", 微软雅黑, Tahoma, Arial, Helvetica, STHeiti; font-size: 13px;"><div data-v-77845de8="" id="p-content"><div data-v-77845de8="" id="doc-body" style="width: calc(100% - 10px); margin-left: 10px;"><div data-v-77845de8="" id="page_md_content" class="page_content_main" style="margin-right: auto; margin-left: auto; height: 9388.88px; overflow: hidden; padding: 10px 10px 90px; color: rgb(51, 51, 51);"><div data-v-77845de8="" id="editor-md" class="main-editor markdown-body editormd-html-preview" style="text-size-adjust: 100%; overflow: auto hidden; font-family: "Microsoft YaHei", Helvetica, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Monaco, monospace, Tahoma, STXihei, 华文细黑, STHeiti, "Helvetica Neue", "Droid Sans", "wenquanyi micro hei", FreeSans, Arimo, Arial, SimSun, 宋体, Heiti, 黑体, sans-serif; font-size: 14px; line-height: 1.75; width: 820px;"><p style="margin-bottom: 1.5em; box-sizing: border-box;">1.截取屏幕的全屏截图:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">这行代码用于截取当前屏幕的全屏截图,并将截图存储在变量img中。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">2.文字识别,默认语言为中文:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> ocr = img.MLKitOcr(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'zh'</span>);
printl(ocr.getJsonString());
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">使用MLKitOcr方法对截图img进行文字识别,指定语言为中文’zh’,并将识别结果以JSON字符串形式打印出来。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">3.获取图片大小(以字节为单位):</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> size = img.byteSize();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片大小: '</span> + size + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">' 字节'</span>);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">4.获取img图片的大小,单位为字节,并打印出来。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">压缩图片,类型为jpg,质量设置为50:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> compressedImg = img.compress(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'jpg'</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">50</span>);
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片压缩成功'</span>);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">5.将截图img压缩为JPEG格式,设置压缩质量为50,并将压缩后的图片存储在compressedImg变量中,然后打印成功信息。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">裁剪图片,裁剪区域为(0,0)到(10,10):</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs apache" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> cutImg = img.cutImage(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">10</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">10</span>);
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">printl</span>('图片裁剪成功');
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">6.对图片img进行裁剪,裁剪区域从坐标(0,0)到(10,10),并将裁剪后的图片存储在cutImg变量中,然后打印成功信息。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">按百分比裁剪图片,裁剪区域为图片的10%到90%:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs apache" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> cutImgPercent = img.cutImagePercent(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>.<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>.<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>.<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">9</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>.<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">9</span>);
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">printl</span>('图片百分比裁剪成功');
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">按照图片宽度和高度的百分比进行裁剪,裁剪区域从图片的10%到90%,并将裁剪后的图片存储在cutImgPercent变量中,然后打印成功信息。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">7.获取图片的bitmap:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> bitmap = img.getBitmap();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'获取图片的bitmap成功'</span>);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">获取图片img的Bitmap对象,Bitmap对象可以用于进一步的图像处理操作,如滤波、裁剪、文字识别等。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">8.获取图片的高度:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> height = img.getHeight();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片高度: '</span> + height);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">获取图片img的高度,并打印出来。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">9.获取图片宽度:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> width = img.getWidth();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片宽度: '</span> + width);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">获取图片img的宽度,并打印出来。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">10.获取图片中心点的RGB值:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs apache" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> centerRGB = img.getPointRGB(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>.<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">5</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>.<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">5</span>);
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">printl</span>('中心点RGB值: ' + centerRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>] + ', ' + centerRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>] + ', ' + centerRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">2</span>]);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">获取图片img中心点的RGB值,并打印出来。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">11.从指定路径读取图片:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> image().read(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'/storage/emulated/0/1.jpg'</span>);
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'读取图片成功'</span> + img);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">从指定路径读取图片,并存储在变量img中,然后打印成功信息。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">12.将base64字符串转换为图片:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs apache" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> img = screen.screenShotFull();
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> imgBase<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">64</span> = img.toBase<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">64</span>();
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> imgFromBase<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">64</span> = new image().readBase<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">64</span>(imgBase<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">64</span>);
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">printl</span>('Base<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">64</span>转图片成功' + imgFromBase<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">64</span>);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">先截取一张全屏截图,然后将其转换为Base64字符串,接着从Base64字符串中读取图片,并存储在imgFromBase64变量中,最后打印成功信息。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">13.释放图片资源:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs less" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">img</span><span class="hljs-selector-class" style="box-sizing: border-box; color: rgb(209, 154, 102);">.recycle</span>();
<span class="hljs-selector-tag" style="box-sizing: border-box; color: rgb(224, 108, 117);">printl</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片资源释放成功'</span>);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">释放图片img占用的资源,然后打印成功信息。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">14.保存图片到指定路径:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> screenshot = screen.screenShotFull();
screenshot.save(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'/sdcard/1.jpg'</span>);
printl(screenshot);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">截取全屏截图并保存到指定路径/sdcard/1.jpg,然后打印截图信息。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">15.将图片转换为base64字符串:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs apache" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> img = screen.screenShotFull();
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> imgBase<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">64</span> = img.toBase<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">64</span>();
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">printl</span>('图片转base<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">64</span>成功: ' + imgBase<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">64</span>);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">截取全屏截图并将其转换为Base64字符串,然后打印转换后的Base64字符串。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">16.将图片转换为jpg格式的base64字符串,质量100:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs apache" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> img = screen.screenShotFull();
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> jpgBase<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">64</span> = img.toJpgBase<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">64</span>(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">100</span>);
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">printl</span>('Jpg格式图片转base<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">64</span>成功: ' + jpgBase<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">64</span>);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">截取全屏截图并将其转换为质量为100的JPEG格式Base64字符串,然后打印转换后的Base64字符串。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">17.输出图片信息为字符串:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> imgInfo = img.toString();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片信息输出: '</span> + imgInfo);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">获取图片img的信息并转换为字符串,最后打印出来。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">18.百分比裁剪图片:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs apache" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> img = screen.screenShotFull();
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> cutImgPercent = img.cutImagePercent(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>.<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>.<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>.<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">9</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>.<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">9</span>);
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">printl</span>('图片百分比裁剪成功' + cutImgPercent);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">再次演示按百分比裁剪图片,裁剪区域从图片的10%到90%,并将裁剪后的图片存储在cutImgPercent变量中,然后打印成功信息。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">19.截取屏幕的全屏截图文字区域识别:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> ocr = img.MLKitOcrRect(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'zh'</span>, [<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>]);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> ocrResult = ocr.getJsonString();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'文字识别结果: '</span> + ocrResult);
img.recycle();
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">截取全屏截图并指定区域进行文字识别(此处为全图),语言为中文,然后打印识别结果的JSON字符串,最后释放图片资源。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">20.压缩图片,类型为jpg,质量设置为50,并保存到指定路径:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">new</span> image().read(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'/storage/emulated/0/1.jpg'</span>);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> compressedImg = img.compress(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'jpg'</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">50</span>);
compressedImg.save(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'/sdcard/compressed_1.jpg'</span>);
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'压缩后的图片已保存: /sdcard/compressed_1.jpg'</span>);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">从指定路径读取图片,压缩为JPEG格式,质量设置为50,然后保存压缩后的图片到指定路径/sdcard/compressed_1.jpg,最后打印成功信息。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">21.获取图片Mat格式:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> mat = img.getMat();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'获取图片的Mat对象成功'</span> + mat);
img.recycle();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片资源释放成功'</span>);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">获取图片img的Mat对象,用于进一步的图像处理操作,然后打印成功信息,最后释放图片资源。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">22.获取图片中心点的RGB值(百分比坐标):</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs apache" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> img = screen.screenShotFull();
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> centerRGB = img.getPointRGB(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>.<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">5</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>.<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">5</span>);
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">printl</span>('中心点RGB值: ' + centerRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>] + ', ' + centerRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>] + ', ' + centerRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">2</span>]);
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">img</span>.recycle();
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">获取全屏截图中中心点的RGB值,并打印出来,最后释放图片资源。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">23.获取图片在真实坐标(100,100)处的RGB值:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs apache" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> img = screen.screenShotFull();
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">var</span> realPointRGB = img.getRealPointRGB(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">100</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">100</span>);
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">printl</span>('真实坐标(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">100</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">100</span>)处的RGB值: ' + realPointRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>] + ', ' + realPointRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>] + ', ' + realPointRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">2</span>]);
<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(152, 195, 121);">img</span>.recycle();
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">获取全屏截图中真实坐标(100,100)处的RGB值,并打印出来,最后释放图片资源。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">24.复制图片对象,并保存复制的图片到指定路径:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs go" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> imgCopy = img.<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">copy</span>();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> savePath = <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'/sdcard/1_copy.jpg'</span>;
imgCopy.save(savePath);
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片复制并保存成功:'</span> + savePath);
img.recycle();
imgCopy.recycle();
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">截取全屏截图并复制图片对象,将复制的图片保存到指定路径/sdcard/1_copy.jpg,然后打印成功信息,并分别释放原图片和复制图片的资源。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">25.使用PaddleOCR进行文字识别处理,隐藏包含特定文本的元素并点击:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs csharp" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> ocrResult = img.paddleOCR(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">640</span>, [<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>]); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 参数:尺寸推荐为640,区域百分数为表示全图</span>
ocrResult.findIncludeText(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"今日头条"</span>).click(); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 假设findIncludeText返回的对象有click方法</span>
img.recycle();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'PaddleOCR处理完成'</span>);
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">使用PaddleOCR对全屏截图进行文字识别,设置尺寸为640,处理全图,然后查找包含特定文本“今日头条”的元素并点击,最后释放图片资源并打印成功信息。</p><p style="margin-bottom: 1.5em; box-sizing: border-box;">26.检查图片对象是否为空:</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><code class="hljs go" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">new</span> image();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (img.isNull()) {
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">println</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片对象为空'</span>);
} <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">else</span> {
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片对象不为空'</span>);
}
img.recycle();
</code></pre><p style="margin-bottom: 1.5em; box-sizing: border-box;">创建一个新的图片对象,并检查该对象是否为空,根据检查结果打印相应的信息,最后释放图片资源。</p><pre style="overflow-wrap: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-stretch: normal; font-size: 12px; line-height: 1.6; font-family: "YaHei Consolas Hybrid", Consolas, "Meiryo UI", "Malgun Gothic", "Segoe UI", "Trebuchet MS", Helvetica, monospace, monospace; box-sizing: border-box; margin-bottom: 1.5em; padding: 1em; overflow: auto; background: rgb(56, 69, 72); border-radius: 4px; border: 1px solid rgb(221, 221, 221); position: relative; color: rgb(209, 210, 210);"><span class="btn-pre-copy" style="box-sizing: border-box; display: block; user-select: none; position: absolute; top: 10px; right: 12px; font-size: 11px; line-height: 1; cursor: pointer; color: rgb(153, 153, 153); transition: color 0.1s ease 0s;">复制</span><code class="hljs go" style="overflow-wrap: normal; box-sizing: border-box; background: 0px 0px transparent; font-family: Consolas, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; border-radius: 3px; border: 0px; word-break: normal; display: block; max-width: none; overflow-x: auto; overflow-y: initial; line-height: inherit;"><span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 截取屏幕的全屏截图</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 文字识别,默认语言为中文</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> ocr = img.MLKitOcr(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'zh'</span>);
printl(ocr.getJsonString());
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 获取图片大小(以字节为单位)</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> size = img.byteSize();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片大小: '</span> + size + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">' 字节'</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 压缩图片,类型为jpg,质量设置为50</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> compressedImg = img.compress(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'jpg'</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">50</span>);
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片压缩成功'</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 裁剪图片,裁剪区域为(0,0)到(10,10)</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> cutImg = img.cutImage(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">10</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">10</span>);
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片裁剪成功'</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 按百分比裁剪图片,裁剪区域为图片的10%到90%</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> cutImgPercent = img.cutImagePercent(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.9</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.9</span>);
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片百分比裁剪成功'</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 获取图片的bitmap</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> bitmap = img.getBitmap();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'获取图片的bitmap成功'</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 获取图片的高度</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> height = img.getHeight();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片高度: '</span> + height);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 获取图片宽度</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> width = img.getWidth();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片宽度: '</span> + width);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 获取图片中心点的RGB值</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> centerRGB = img.getPointRGB(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.5</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.5</span>);
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'中心点RGB值: '</span> + centerRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>] + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">', '</span> + centerRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>] + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">', '</span> + centerRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">2</span>]);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 从指定路径读取图片</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img =<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">new</span> image().read(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'/storage/emulated/0/1.jpg'</span>)
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'读取图片成功'</span>+img);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 将base64字符串转换为图片</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> imgBase64 = img.toBase64();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> imgFromBase64 = <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">new</span> image().readBase64(imgBase64);
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'Base64转图片成功'</span>+imgFromBase64);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 释放图片资源</span>
img.recycle();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片资源释放成功'</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 保存图片到指定路径</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> screenshot = screen.screenShotFull();
screenshot.save(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'/sdcard/1.jpg'</span>);
printl(screenshot);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 将图片转换为base64字符串</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> imgBase64 = img.toBase64();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片转base64成功: '</span> + imgBase64);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 将图片转换为jpg格式的base64字符串,质量100</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> imgBase64 = img.toBase64();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> jpgBase64 = img.toJpgBase64(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">100</span>);
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'Jpg格式图片转base64成功: '</span> + jpgBase64);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 输出图片信息为字符串</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> imgInfo = img.toString();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片信息输出: '</span> + imgInfo);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 百分比裁剪图片</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> cutImgPercent = img.cutImagePercent(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.9</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.9</span>);
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片百分比裁剪成功'</span>+cutImgPercent);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 截取屏幕的全屏截图文字区域识别</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> ocr = img.MLKitOcrRect(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'zh'</span>, [<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>]);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> ocrResult = ocr.getJsonString();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'文字识别结果: '</span> + ocrResult);
img.recycle();
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 获取图片大小(以字节为单位)</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> size = img.byteSize();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片大小: '</span> + size + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">' 字节'</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 压缩图片,类型为jpg,质量设置为50</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">new</span> image().read(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'/storage/emulated/0/1.jpg'</span>);
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> compressedImg = img.compress(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'jpg'</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">50</span>);<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 压缩图片,类型为jpg,质量设置为50</span>
compressedImg.save(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'/sdcard/compressed_1.jpg'</span>);<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 保存压缩后的图片到指定路径</span>
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'压缩后的图片已保存: /sdcard/compressed_1.jpg'</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 获取图片Mat格式</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> bitmap = img.getBitmap();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> mat = img.getMat();<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">//Mat 对象可以用于进一步的图像处理操作,比如滤波、裁剪、文字识别等</span>
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'获取图片的Mat对象成功'</span>+mat);
img.recycle();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片资源释放成功'</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 获取图片的中心点的RGB值,百分比座标</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> centerRGB = img.getPointRGB(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.5</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0.5</span>);
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'中心点RGB值: '</span> + centerRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>] + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">', '</span> + centerRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>] + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">', '</span> + centerRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">2</span>]);
img.recycle();
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 获取图片在真实坐标(100,100)处的RGB值</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> realPointRGB = img.getRealPointRGB(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">100</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">100</span>);
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'真实坐标(100, 100)处的RGB值: '</span> + realPointRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>] + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">', '</span> + realPointRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>] + <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">', '</span> + realPointRGB[<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">2</span>]);
img.recycle();
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 复制图片对象,保存复制的图片到指定路径</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> imgCopy = img.<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">copy</span>();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> savePath = <span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'/sdcard/1_copy.jpg'</span>;
imgCopy.save(savePath);
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片复制并保存成功:'</span> + savePath);
img.recycle();
imgCopy.recycle();
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 使用 PaddleOCR 进行文字识别处理 OCR 结果,此处假设有一个方法 findIncludeText 可以隐藏包含特定文本的元素</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = screen.screenShotFull();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> ocrResult = img.paddleOCR(<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">640</span>, [<span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">0</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>, <span class="hljs-number" style="box-sizing: border-box; color: rgb(209, 154, 102);">1</span>]); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 参数:尺寸推荐为640,区域百分数为表示全图</span>
ocrResult.findIncludeText(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">"今日头条"</span>).click(); <span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 假设 findIncludeText 返回的对象有 click 方法</span>
img.recycle();
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'PaddleOCR 处理完成'</span>);
<span class="hljs-comment" style="box-sizing: border-box; color: rgb(170, 170, 170); font-style: italic;">// 检查图片对象是否为空</span>
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">var</span> img = <span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">new</span> image();
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">if</span> (img.isNull()) {
<span class="hljs-built_in" style="box-sizing: border-box; color: rgb(230, 192, 123);">println</span>(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片对象为空'</span>);
} <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(198, 120, 221);">else</span> {
printl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(152, 195, 121);">'图片对象不为空'</span>);
}
img.recycle();
</code><div><br></div></pre></div></div></div></div></div></td></tr></tbody></table></div>
页:
[1]