【问题标题】:Shrink image in iphone 7 xamarin ios?在 iphone 7 xamarin ios 中缩小图像?
【发布时间】:2017-02-24 13:36:09
【问题描述】:

我在 xamarin.ios 工作。我正在使用相机拍摄照片并尝试将其上传到服务器上。但是当我尝试将它上传到服务器时,我得到了“TargetInvocationException”。但是当我在 Ipad 上运行相同的代码时,一切正常。

以下是代码:

  Camera.TakePicture(this, (obj) =>
            {
                var photo = obj.ValueForKey(new NSString("UIImagePickerControllerOriginalImage")) as UIImage;
                Byte[] myByteArray;
                using (NSData imageData = photo.AsJPEG(0.0f))
                {
                    //myByteArray = imageData.ToArray();
                    myByteArray = new Byte[imageData.Length];
                    System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, myByteArray, 0, Convert.ToInt32(imageData.Length));
                }

                ImageLoaderPopup imageLoader = new ImageLoaderPopup(this, selectedWorkOrder, myByteArray, title);
                imageLoader.PopUp(true, delegate { });
            });

有人知道我为什么会遇到这个问题吗?我做错了什么?

【问题讨论】:

  • 你能从你看到的TargetInvocationException 添加整个堆栈跟踪吗?

标签: ios xamarin xamarin.ios ios-camera


【解决方案1】:

您可能对 Picker 返回的图像大小有疑问。使用 iPhone 7 拍摄的图像尺寸很大。

您只需要在使用 Scale 方法上传原始图像并设置您认为可以接受的大小之前将其缩小。

var smallImage = image.Scale(new CGSize(1280, 720)); //Or the size you need.

更新

您只需要上面提到的 Scale 方法。

Xamarin 开源的一大优势在于,您可以随时查看内部​​结构。

https://github.com/xamarin/xamarin-macios/blob/master/src/UIKit/UIImage.cs#L66

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-05
    • 1970-01-01
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-19
    • 1970-01-01
    相关资源
    最近更新 更多