How to load UIImage from web URL ?

How to load UIImage from web URL ?

UIImage img=Images.Fromuri("www.google.com/my.jpg");

Common Class :

public static Class Images
{
Public static UIImage FromUrl (string uri)
{
using (var url = new NSUrl (uri))
using (var data = NSData.FromUrl (url))
return UIImage.LoadFromData (data);
}
}
How to choose a photo From Phone album?

In Xamarin.iOS Application for choose a photo from album .we need to use UIImagePickerController

Follow below step for show photo album Controller

1. Create the image picker control

Var Imagepicker=new UIImagePickerController();

2. Set the Source and media Type

Imagepicker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;

Imagepicker.MediaTypes = UIImagePickerController.AvailableMediaTypes (UIImagePickerControllerSourceType.PhotoLibrary);

3.Create Delegate event for image chose & cancel image selection.

Imagepicker.FinishedPickingMedia += Handle_FinishedPickingMedia;

Imagepicker.Canceled += Handle_Canceled;

4.Show Image controller

NavigationController.PresentModalViewController(Imagepicker, true);

5. Implement Image choose event

protected void Handle_FinishedPickingMedia (object sender, UIImagePickerMediaPickedEventArgs e)
{
// determine what was selected, video or image
bool isImage = false;
switch(e.Info[UIImagePickerController.MediaType].ToString()) {
case "public.image":
// get the original image
UIImage originalImage = e.Info[UIImagePickerController.OriginalImage] as UIImage;
if(originalImage != null) {
// do something with the image
Console.WriteLine ("got the original image");
imageView.Image = originalImage; // display
break;
case "public.video":
Console.WriteLine("Video selected");
break;
}
// dismiss the picker
imagePicker.DismissModalViewControllerAnimated (true);
}
6 .Cancel Image controller
void Handle_Canceled (object sender, EventArgs e) {
Imagepicker.DismissModalViewControllerAnimated(true);
}
3. Which controller we can use for Phone photo album access?

UIImagePickerController

0 Comments

Featured Post

Improving C# Performance by Using AsSpan and Avoiding Substring

During development and everyday use, Substring is often the go-to choice for string manipulation. However, there are cases where Substring c...

MSDEVBUILD - English Channel

MSDEVBUILD - Tamil Channel

Popular Posts