Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8054731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:12:58+00:00 2026-06-05T08:12:58+00:00

I´ve done a picture selector via UIImagePickerController. Because of the memory issues this one

  • 0

I´ve done a picture selector via UIImagePickerController. Because of the memory issues this one has I want to save the selected image to disc and if needed load it from filepath. But I can´t manage to get it working.

If i bind the original image directly it is displayed with no problems.

File.Exists in the code returns true but image in the last line is null if watched in debugger.. Thank you very much for your help!

                    NSData data = originalImage.AsPNG();

                    string path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
                    string pathTempImage = Path.Combine(path, "tempImage.png");

                    byte[] tempImage = new byte[data.Length];

                    File.WriteAllBytes(pathTempImage, tempImage);

                    if(File.Exists(pathTempImage))
                    {
                        int i = 0;
                    }

                    UIImage image = UIImage.FromFile(pathTempImage);

Update

This is the code that works for me:

void HandleFinishedPickingMedia (object sender, UIImagePickerMediaPickedEventArgs e)
    {
        _view.DismissModalViewControllerAnimated (true);

        BackgroundWorker bw = new BackgroundWorker();

        bw.DoWork += delegate(object bwsender, DoWorkEventArgs e2) {
            // determine what was selected, video or image
            bool isImage = false;
            switch(e.Info[UIImagePickerController.MediaType].ToString()) {
                case "public.image":
                    Console.WriteLine("Image selected");
                    isImage = true;
                    break;
                case "public.video":
                    Console.WriteLine("Video selected");
                    break;
            }

            // get common info (shared between images and video)
            NSUrl referenceURL = e.Info[new NSString("UIImagePickerControllerReferenceUrl")] as NSUrl;
            if (referenceURL != null)
                Console.WriteLine("Url:"+referenceURL.ToString ());

            // if it was an image, get the other image info
            if(isImage) {
                // get the original image  
                originalImage = e.Info[UIImagePickerController.OriginalImage] as UIImage;
                if(originalImage != null) {
                    NSData data = originalImage.AsPNG();
                    _picture = new byte[data.Length];

                    ImageResizer resizer = new ImageResizer(originalImage);
                    resizer.RatioResize(200,200);

                    string path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
                    string pathTempImage = Path.Combine(path, "tempImage.png");
                    string filePath = Path.Combine(path, "OriginalImage.png");

                    NSData dataTempImage = resizer.ModifiedImage.AsPNG();
                    byte[] tempImage = new byte[dataTempImage.Length];

                    System.Runtime.InteropServices.Marshal.Copy(dataTempImage.Bytes,tempImage,0,Convert.ToInt32(tempImage.Length));

                    //OriginalImage
                    File.WriteAllBytes(filePath, _picture); 

                    //TempImag
                    File.WriteAllBytes(pathTempImage, tempImage);


                    UIImage image = UIImage.FromFile(pathTempImage);

                    _view.InvokeOnMainThread (delegate {
                        templateCell.BindDataToCell(appSelectPicture.Label, image);
                    });

                    _picture = null;
                }
            } else { // if it's a video
                // get video url
                NSUrl mediaURL = e.Info[UIImagePickerController.MediaURL] as NSUrl;
                if(mediaURL != null) {
                    Console.WriteLine(mediaURL.ToString());
                }
            }          
            // dismiss the picker
        };

        bw.RunWorkerAsync();

        bw.RunWorkerCompleted += HandleRunWorkerCompleted;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:12:59+00:00Added an answer on June 5, 2026 at 8:12 am
    byte[] tempImage = new byte[data.Length];
    File.WriteAllBytes(pathTempImage, tempImage);
    

    You’re not copying the image data to your allocated array before saving it. That result in a large empty file that is not a valid image.

    Try using one of the NSData.Save overloads, like:

    NSError error;
    data.Save (pathTempImage, NSDataWritingOptions.FileProtectionNone, out error);
    

    That will allow you to avoid allocating the byte[] array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Done quite a lot of searching around this one and so far I've only
Has anyone successfully done this? My idea is to post to a servlet and
I want to use a picture as my website design. It's a plain one,
User has pets , pets may have pictures One picture may be set as
Comparing must work on-the-fly, so this must be done via javascript or with php
Loading the image one time works as done in the following steps (for code
this is very confusing for me, cannot picture how it can be done. I
I have done this one for converting the byte of array in one of
I done few phone gap projects before, This time a new exception raised in
I have already done to convert UIView into UIImage but i want that any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.