简体   繁体   中英

Capture Image From Camera set to ImageView

How to upload or add an Image to UIImageView directly from iPhone/Ipad Captured camera Image.

I have uploaded an image to UIImageView from photo library.

Now, I want upload an image directly after taken an image through camera to ImageView.

Please suggest me how to implement this.

using IOS 8.0

This can be accomplished very easily with the Xamarin.Mobile component, which is free and works with all platforms.

http://components.xamarin.com/view/xamarin.mobile

From the example they give:

using Xamarin.Media;
// ...

var picker = new MediaPicker ();
if (!picker.IsCameraAvailable)
    Console.WriteLine ("No camera!");
else {
    try {
        MediaFile file = await picker.TakePhotoAsync (new StoreCameraMediaOptions {
            Name = "test.jpg",
            Directory = "MediaPickerSample"
        });

        Console.WriteLine (file.Path);
    } catch (OperationCanceledException) {
        Console.WriteLine ("Canceled");
    }
}

After you take the picture, it is saved to the directory you specified, with the name you specified. To easily retrieve this picture and display it with your ImageView using the above example you can do the following:

//file is declared above as type MediaFile
UIImage image = new UIImage(file.Path);

//Fill in with whatever your ImageView is
yourImageView.Image = image;

Edit:

Just a note that the above needs to be asynchronous. So if you want to launch the camera from a button call, for instance, you just slightly modify the .TouchUpInside event:

exampleButton.TouchUpInside += async (object sender, EventArgs e) => {
  //Code from above goes in here, make sure you have async after the +=
};

Otherwise you could wrap the code from above in a function and add async to that:

public async void CaptureImage()
{
    //Code from above goes here
}

You will need to use AVFoundation to do this. Check out the AVCam sample project in Xcode:

https://developer.apple.com/library/ios/samplecode/AVCam/Introduction/Intro.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM