area black in export image with method "save" control sfchart

attached image exported from the sfchart control, it has a black area.

What is this area?

my control is inside a pivot control

<Pivot Grid.Column="1" Grid.Row="1" Background="White" x:Name="rootPivot" Margin="0" Padding="0" SelectionChanged="rootPivot_SelectionChanged">
            <PivotItem   Header="Piso Asegurado"  Margin="0" HorizontalAlignment="Left">
                
                <Custom:SfChart Name="xxgraficoPa" AreaBackground="White" Background="White" LayoutUpdated="xxgraficoPa_LayoutUpdated" Margin="10,10,10,10"  HorizontalAlignment="Left" Height="auto" Width="auto"  VerticalAlignment="Top"/>
            </PivotItem>

.................
.............
.................


my code 

 Random rnd = new Random();
  nombreArchivo = DateTime.Now.ToString("yyyyMMddhhmmss") + rnd.Next(52).ToString() + ".png";
 this.xxgraficoPa.Save(nombreArchivo, ApplicationData.Current.LocalFolder);

How do I eliminate the black area?


atach


Attachment: LocalState_216b2dbb.zip

3 Replies

MK Muneesh Kumar G Syncfusion Team May 24, 2018 10:45 AM UTC

Hi Diego,  
 
Thanks for your Syncfusion products.  
  
We have analyzed the reported problem and we found that exported image with black is due to SfChart margin. So, we have exported the SfChart parent to image directly as per the below code snippet. 
 
Code snippet [C#]: 
  private async void Save(object parameter) 
        { 
            if (parameter != null) 
            { 
                var grid = parameter as Grid; 
                var renderTargetBitmap = new RenderTargetBitmap(); 
                await renderTargetBitmap.RenderAsync(grid); 
                var pixels = await renderTargetBitmap.GetPixelsAsync(); 
 
 
                var fileSavePicker = new FileSavePicker(); 
                fileSavePicker.FileTypeChoices.Add("BMP", new List<string>() { ".bmp" }); 
                fileSavePicker.FileTypeChoices.Add("GIF", new List<string>() { ".gif" }); 
                fileSavePicker.FileTypeChoices.Add("PNG", new List<string>() { ".png" }); 
                fileSavePicker.FileTypeChoices.Add("JPG", new List<string>() { ".jpg" }); 
                fileSavePicker.FileTypeChoices.Add("JPG-XR", new List<string>() { ".jxr" }); 
                fileSavePicker.FileTypeChoices.Add("TIFF", new List<string>() { ".tiff" }); 
                fileSavePicker.SuggestedFileName = SfChartResourceWrapper.FileName; 
 
                var file = await fileSavePicker.PickSaveFileAsync(); 
                if (file != null) 
                { 
                    Guid encoderId = GetBitmapEncoderId(file.FileType); 
                    using (var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite)) 
                    { 
                        var encoder = await BitmapEncoder.CreateAsync(encoderId, stream); 
                        encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)renderTargetBitmap.PixelWidth, 
                            (uint)renderTargetBitmap.PixelHeight, imageResolution, imageResolution, pixels.ToArray()); 
                        await encoder.FlushAsync(); 
                    } 
                } 
            } 
        } 
 
We have prepared a sample based on this, please find the sample from the following location.  
 
 
Please let us know if you have any queries.  
 
Regards,  
Muneesh Kumar G. 
 
 



DS DIEGO SEBASTIAN May 24, 2018 03:21 PM UTC

I want to create the file automatically but I have an error, you could help me. I want to create that file in the application directory.


Note: your code run perfect, i necesit file create automatically

this my code 

var grid = this.padre as Grid;
            var renderTargetBitmap = new Windows.UI.Xaml.Media.Imaging.RenderTargetBitmap();
            await renderTargetBitmap.RenderAsync(grid);
            var pixels = await renderTargetBitmap.GetPixelsAsync();
            // Create sample file; replace if exists
            Random rnd = new Random();
            nombreArchivo = DateTime.Now.ToString("yyyyMMddhhmmss") + rnd.Next(52).ToString() + ".png";

            Windows.Storage.StorageFolder storageFolder =
                Windows.Storage.ApplicationData.Current.LocalFolder;
            Windows.Storage.StorageFile fileexport =
                await storageFolder.CreateFileAsync(nombreArchivo,
                    Windows.Storage.CreationCollisionOption.ReplaceExisting);


            StorageFile imageFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(nombreArchivo, CreationCollisionOption.ReplaceExisting);
            Guid encoderId = GetBitmapEncoderId(imageFile.FileType);

            using (var stream = await imageFile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite))
            {
                var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateAsync(encoderId, stream);
                encoder.SetPixelData(Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8, Windows.Graphics.Imaging.BitmapAlphaMode.Ignore, (uint)renderTargetBitmap.PixelWidth,
                    (uint)renderTargetBitmap.PixelHeight, 96.0, 96.0, pixels.ToArray());
                await encoder.FlushAsync();
            }


MK Muneesh Kumar G Syncfusion Team May 25, 2018 07:31 AM UTC

Hi Diego,   
  
Based on your requirement we have exported the image in application directory. We have modified the sample based using your code the sample works fine. Can you please check the sample in the following location? 
 
 
Please let us know the exception details if you are still facing any issue in this. 
 
Thanks, 
Muneesh Kumar G. 
 


Loader.
Up arrow icon