Forum Xamarin.Forms

Problem On Taking Picture With Media Plugin

SametErapSametErap USMember

Shortly, I need to resize the image that is picked from gallery or taken with camera because of an Image Control does not show big size images. I utilized the following link : (By the way, the project is PCL)

https://forums.xamarin.com/discussion/comment/271282

At this section;

        byte[] myfile;

        using (var memoryStream = new MemoryStream())
        {
           var st =  _mediaFile.GetStream();
            st.CopyTo(memoryStream);
            _mediaFile.Dispose();
            myfile = memoryStream.ToArray();
        }

If I use the following;
_mediaFile = await CrossMedia.Current.PickPhotoAsync();

and If you check st(variable above), everything works fine and I'm able to resize the image using byte[] myFile.

But, If I use the following;

           _mediaFile = await CrossMedia.Current.TakePhotoAsync(
            new Plugin.Media.Abstractions.StoreCameraMediaOptions
            {
                Directory = "MediaPluginPhoto",
                Name = DateTime.Now + ".jpg",
                DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Front,


            });

and If you check st(variable above), the image is not complete and when you convert it to byte[], width and height are only 1, but it should be the actual size of the image. And the image size (when you upload to server) is 1KB.

However, if the same image is picked from gallery, everything works properly.

If you faced this kind of problem, what was your solution ?

Thanks

Answers

  • TEastmanTEastman USMember ✭✭

    I am not sure how to do it with byte[], but here is how I resize my images with the same media plugin

    _mediaFile = await CrossMedia.Current.TakePhotoAsync(
                new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "MediaPluginPhoto",
                    Name = DateTime.Now + ".jpg",
                    DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Front,
    
                        // RESET PHOTO SIZE
                        // By default the photo that is taken/picked is the maxiumum size and quality available. 
                        // For most applications this is not needed and can be Resized. 
                        // This can be accomplished by adjusting the PhotoSize property on the options. 
                        // The easiest is to adjust it to Small, Medium, or Large, which is 25%, 50%, or 75% or the original.
    
                        // Photo Size options examples
    
                        //PhotoSize = PhotoSize.Medium,
    
                        //PhotoSize = PhotoSize.Custom,
                        CustomPhotoSize = 90, // Resize to 90% of original
    
                        // PHOTO QUALITY
                        // Set the CompressionQuality, which is a value from 0 the most compressed all the way to 100, which is no compression.
                        // A good setting from testing is around 92
                        CompressionQuality = 92,
                });
    
Sign In or Register to comment.