locked
Why Mail option is not available when sharing Image in Windows 8 application? RRS feed

  • Question

  • Am trying to `share an Image` via `Share charm`, but in the charm '`Mail`' application not available so that couldn't share image through mail . But i tried to share the same image via `Native Photo app` & there `Mail` option available. 





    Below my code

            private async void OnDataRequested(DataTransferManager sender, DataRequestedEventArgs e)
            {
            DataRequestDeferral deferral = e.Request.GetDeferral();

            DataPackage requestData = e.Request.Data;
            requestData.Properties.Title = "Image";
            IRandomAccessStream stream = new InMemoryRandomAccessStream();
            Guid encoderId;
            switch (file.FileType)
            {
                case ".png":
                    encoderId = BitmapEncoder.PngEncoderId;
                    break;
                case ".jpg":
                case ".jpeg":
                default:
                    encoderId = BitmapEncoder.JpegEncoderId;
                    break;
            }
            BitmapEncoder encoder = await BitmapEncoder.CreateAsync(encoderId, stream);
            Stream pixelStream = image.PixelBuffer.AsStream();
            byte[] pixels = new byte[pixelStream.Length];
            await pixelStream.ReadAsync(pixels, 0, pixels.Length);
            encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)image.PixelWidth, (uint)image.PixelHeight, 96.0, 96.0, pixels);
            requestData.SetBitmap(RandomAccessStreamReference.CreateFromStream(stream));
            await encoder.FlushAsync();

            deferral.Complete();
        }
     


    Am i missed anything there in my code?

    Friday, October 18, 2013 5:46 AM

All replies

  • The mail app is not a target for images. You have to save your image and share it as a StorageItem:

    var file = await ApplicationData.Current.LocalFolder.GetFileAsync("yourImage.png");
    var images = new List<IStorageItem>();
    images.Add(file);
    requestData.SetStorageItems(images);

    As an alternative, you could also share as HTML which is explained here.

    Friday, October 18, 2013 6:30 AM
  • The mail app is not a target for images. You have to save your image and share it as a StorageItem:

    var file = await ApplicationData.Current.LocalFolder.GetFileAsync("yourImage.png");
    var images = new List<IStorageItem>();
    images.Add(file);
    requestData.SetStorageItems(images);

    As an alternative, you could also share as HTML which is explained here.

    Thanks Diederik for your answer.

    Additionally i was getting an error message says "Something went wrong Couldn't share Image" frequently while sharing the image  after saving it to the storage. I found some useful links here  How to share a file that has been created on the fly and Share Contract Closes Immediately

    Friday, October 18, 2013 6:54 AM