UiPath Documentation
activities
latest
false
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。
UiPath logo, featuring letters U and I in white

Document Understanding 活动

上次更新日期 2026年4月22日

OCR 异步代码活动类

定义

  • 命名空间: UiPath.OCR.Contracts.Activities
  • 程序集: UiPath.OCR.Contracts

描述

必须实现的抽象类,才能从 Workflow Foundation 框架构造 AsyncCodeActivity

成员

方法
  • BeforeExecute(System.Activities.AsyncCodeActivityContext, System.AsyncCallback, object) System.Collections.Generic.Dictionary<string, object> - 覆盖此方法以计算并提供除Image参数以外的所有活动输入参数,并以字典形式返回活动输入参数,其中键为参数名称,值为参数值。
    备注:

    At design time, when no contexts are available, the method's parameters are null. In this case, the activity arguments can't be read, so you may want to provide default values for them.

  • BeginExecute(System.Activities.AsyncCodeActivityContext, System.AsyncCallback, object) System.IAsyncResult - 您可以覆盖此方法以实施活动代码。 由工作流运行时调用,以异步执行活动。 它还提供对跟踪、变量和参数的访问权限。
  • EndExecute(System.Activities.AsyncCodeActivityContext, System.IAsyncResult) - System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.Drawing.Rectangle, string>> - 您可以覆盖此方法,以通知工作流运行时关联的异步活动操作已完成。
  • OCRAsyncCodeActivity()
  • OnSuccess(System.Activities.AsyncCodeActivityContext, UiPath.OCR.Contracts.DataContracts.OCRResult) void OnSuccess - 计算 OCR 结果后调用此方法。 它可用于设置输出参数或任何其他最终操作。
  • PerformOCRAsync(System.Drawing.Image, System.Collections.Generic.Dictionary<string, object>, System.Threading.CancellationToken) System.Threading.Tasks.Task<UiPath.OCR.Contracts.DataContracts.OCRResult> - Processes an image and returns the extracted text information. The options parameter is a dictionary of activity arguments having as key the argument name and as value the argument value.
属性
  • ExtractWords - 获取或设置是否应提取单词。
  • Image System.Activities.InArgument<System.Drawing.Image> - 要处理的图像。
  • Language System.Activities.InArgument<string> - OCR 引擎从用户界面元素中提取字符串所使用的语言。 对于 Google OCR 引擎,该字段需要包含语言文件前缀,如表示罗马尼亚语的“ron”、表示意大利语的“ita”以及表示法语的“fra”。 您可以在该页面找到支持的语言前缀。
  • Output System.Activities.OutArgument<UiPath.OCR.Contracts.OcrActivityResult> - 活动输出。 Legacy,过时的参数。
  • Text System.Activities.OutArgument<string> - 文字的文本值。

代码示例

[DisplayName("Sample OCRAsyncCodeActivity")]
internal class SampleOCRAsyncCodeActivity : OCRAsyncCodeActivity
    {
        [Browsable(true)]
        public override InArgument<Image> Image { get; set; }

        public InArgument<string> CustomInput { get; set; }

        public OutArgument<string> CustomOutput { get; set; }

        public override Task<OCRResult> PerformOCRAsync(Image image, Dictionary<string, object> options, CancellationToken ct)
        {
            string customInput = options[nameof(CustomInput)] as string;
            string text = $"Text from {nameof(SampleOCRAsyncCodeActivity)} with custom input: {customInput}";
            return Task.FromResult(OCRResultHelper.FromText(text));
        }

        protected override void OnSuccess(AsyncCodeActivityContext context, OCRResult result)
        {
            CustomOutput.Set(context, $"Custom output: '{result.Text}' has {result.Words.Length} words.");
        }

        protected override Dictionary<string, object> BeforeExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            return new Dictionary<string, object>
            {
                { nameof(CustomInput), CustomInput.Get(context) }
            };
        }
    }
[DisplayName("Sample OCRAsyncCodeActivity")]
internal class SampleOCRAsyncCodeActivity : OCRAsyncCodeActivity
    {
        [Browsable(true)]
        public override InArgument<Image> Image { get; set; }

        public InArgument<string> CustomInput { get; set; }

        public OutArgument<string> CustomOutput { get; set; }

        public override Task<OCRResult> PerformOCRAsync(Image image, Dictionary<string, object> options, CancellationToken ct)
        {
            string customInput = options[nameof(CustomInput)] as string;
            string text = $"Text from {nameof(SampleOCRAsyncCodeActivity)} with custom input: {customInput}";
            return Task.FromResult(OCRResultHelper.FromText(text));
        }

        protected override void OnSuccess(AsyncCodeActivityContext context, OCRResult result)
        {
            CustomOutput.Set(context, $"Custom output: '{result.Text}' has {result.Words.Length} words.");
        }

        protected override Dictionary<string, object> BeforeExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            return new Dictionary<string, object>
            {
                { nameof(CustomInput), CustomInput.Get(context) }
            };
        }
    }
  • 定义
  • 描述
  • 成员
  • 代码示例

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新