Exemplo n.º 1
0
 private void LoadImageFile(ImageFileSourceData source)
 {
     EasyARController.Instance.StartCoroutine(FileUtil.LoadFile(source.Path, source.PathType, (Buffer buffer) =>
     {
         EasyARController.Instance.StartCoroutine(LoadImageBuffer(buffer.Clone(), source));
     }));
 }
Exemplo n.º 2
0
        private IEnumerator LoadImageBuffer(Buffer buffer, ImageFileSourceData source)
        {
            using (buffer)
            {
                Optional <Image> imageOptional = null;
                bool             taskFinished  = false;
                EasyARController.Instance.Worker.Run(() =>
                {
                    imageOptional = ImageHelper.decode(buffer);
                    taskFinished  = true;
                });

                while (!taskFinished)
                {
                    yield return(0);
                }
                if (imageOptional.OnNone)
                {
                    throw new Exception("invalid buffer");
                }

                using (var image = imageOptional.Value)
                    using (var param = new ImageTargetParameters())
                    {
                        param.setImage(image);
                        param.setName(source.Name);
                        param.setScale(source.Scale);
                        param.setUid(Guid.NewGuid().ToString());
                        param.setMeta(string.Empty);
                        var targetOptional = ImageTarget.createFromParameters(param);
                        if (targetOptional.OnSome)
                        {
                            Target = targetOptional.Value;
                            if (Target != null && TargetAvailable != null)
                            {
                                TargetAvailable();
                            }
                        }
                        else
                        {
                            throw new Exception("invalid parameter");
                        }
                    }
            }
            UpdateTargetInTracker();
        }