|
| 1 | +--- |
| 2 | +title: Exporting FloatingChartShape to Bitmap in RadSpreadsheet for WinForms |
| 3 | +description: Learn how to export FloatingChartShape from RadSpreadsheet to a Bitmap image in WinForms applications. |
| 4 | +type: how-to |
| 5 | +page_title: How to Exporting FloatingChartShape to Bitmap in RadSpreadsheet for WinForms |
| 6 | +slug: convert-floatingchartshape-to-bitmap-radspreadsheet-winforms |
| 7 | +tags: spreadsheet, winforms, floatingchartshape, bitmap, export |
| 8 | +res_type: kb |
| 9 | +ticketid: 1631289 |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +|Product Version|Product|Author| |
| 15 | +|----|----|----| |
| 16 | +|2024.4.1113|RadSpreadsheet for WinForms|[Dinko Krastev](https://www.telerik.com/blogs/author/dinko-krastev)| |
| 17 | + |
| 18 | +## Description |
| 19 | + |
| 20 | +In RadSpreadsheet for WinForms, you may need to convert a `FloatingChartShape` to a bitmap image. Unlike `RadChartView` which offers a direct `DrawToBitMap()` method, `FloatingChartShape` requires a different approach for exporting to a bitmap. |
| 21 | + |
| 22 | +## Solution |
| 23 | + |
| 24 | +To export a `FloatingChartShape` from a `RadSpreadsheet` to a bitmap, utilize the `ChartModelToImageConverter.GetImageFromFloatingChartShape()` method. This method accepts the `FloatingChartShape` as its first parameter and the desired image size as its second parameter. It returns an `Image` object, which you can then save to a file in PNG format or any other supported format. |
| 25 | + |
| 26 | +Below is an example code snippet that demonstrates how to achieve this: |
| 27 | + |
| 28 | +````C# |
| 29 | +private void ExportChartToImage() |
| 30 | +{ |
| 31 | + var worksheet = this.radSpreadsheet1.Workbook.Sheets[0] as Worksheet; |
| 32 | + var image = Telerik.WinForms.Controls.Spreadsheet.Layers.ChartModelToImageConverter.GetImageFromFloatingChartShape(worksheet.Charts[0], new Size(780, 588)); |
| 33 | + image.Save("Chart.png", System.Drawing.Imaging.ImageFormat.Png); |
| 34 | +} |
| 35 | +```` |
| 36 | + |
| 37 | +In this example, the `ExportChartToImage` method retrieves the first chart from the worksheet, converts it to an image with the specified size, and then saves the image as a PNG file named "Chart.png". |
| 38 | + |
| 39 | +## See Also |
| 40 | + |
| 41 | +- [RadSpreadsheet Documentation](https://docs.telerik.com/devtools/winforms/controls/radspreadsheet/overview) |
| 42 | +- [RadSpreadsheet Workbook Overview](https://docs.telerik.com/devtools/winforms/controls/radspreadsheet/model/workbook) |
| 43 | +- [RadSpreadsheet Chart Shapes](https://docs.telerik.com/devtools/winforms/controls/radspreadsheet/features/chart-shapes) |
0 commit comments