save GridControl to image
Hello,
Is it possible to save the GridControl in an image?
Many thanks.
I have a GridControl which contains RadialGauge and Buttons (see image)
Is it possible to save the GridControl in an image?
Many thanks.
Beppe
SIGN IN To post a reply.
9 Replies
MG
Mohanraj Gunasekaran
Syncfusion Team
July 9, 2018 09:45 AM UTC
Hi Beppe,
Thanks for using Syncfusion product.
In order to save the GridControl appearance as an image, you can use the Control.DrawToBitMap method to draw the grid in view to BitMap format and this bitmap image can be saved by using BitMap.Save method. Please refer to the below code example and the sample,
Code example
|
Bitmap bitMap = new Bitmap(this.gridControl1.ClientRectangle.Width, this.gridControl1.ClientRectangle.Height);
this.gridControl1.DrawToBitmap(bmp, new Rectangle(0, 0, bmp.Width, bmp.Height));
//To save the image locally.
bmp.Save("GridControl.png"); |
Sample link: GridControl
Regards,
Mohanraj G
BS
BEPPE SALVADERI
July 9, 2018 09:33 PM UTC
Hi Mohanraj,
thanks for the reply.
The method you suggested works but saves only the portion of GridControl displayed. I have to save all the GridControl, is it possible?
Many thanks.
Beppe
MG
Mohanraj Gunasekaran
Syncfusion Team
July 10, 2018 05:00 PM UTC
Hi Beppe,
Thanks for your update.
By default, GridControl does not have the support to convert the full row as an image. But, you can achieve your scenario by converting the Grid to pdf and make the pdf as an image.
We have prepared the sample based on your requirement. Please refer to the below attached sample,
Sample link: GridControl
Regards,
Mohanraj G
BS
BEPPE SALVADERI
July 11, 2018 09:02 PM UTC
Hi, Mohanraj ,
thanks for the example but at line 54 I get this error:
Error CS1061 'PdfLoadedDocument' does not contain a definition for 'ImageExportSettings' and no extension method 'ImageExportSettings' accepting a first argument of type 'PdfLoadedDocument' could be found (are you missing a using directive or an assembly reference?)
is it possible to have the example in VB Net language?
Many thanks for your collaboration.
Beppe
MG
Mohanraj Gunasekaran
Syncfusion Team
July 12, 2018 09:06 AM UTC
Hi Beppe,
Sorry for the inconvenience.
|
Query |
Solution |
|
Error CS1061 'PdfLoadedDocument' does not contain a definition for 'ImageExportSettings' and no extension method 'ImageExportSettings' accepting a first argument of type 'PdfLoadedDocument' could be found (are you missing a using directive or an assembly reference?) |
We have prepared a sample based on our latest version 16.2.0.41. Seems that you are using the older version. There is no need to use this property for exporting the grid to pdf. Moreover, we have modified sample here. |
|
is it possible to have the example in VB Net language? |
We have prepared the sample in vb.Net as per your request. We have done the following changes in attached sample in order to achieve the grid to image saving with the control cell type as it is.
We have implemented the CustomCellRenderer for Control CellType to adjust the image size while converting to pdf using PrintingMode property in OnDraw method to avoid the image overlapping issue. So, please make use of the below custom cell renderer to overcome the mentioned issue. Please refer to the below code example,
Code example
Me.gridControl1.CellRenderers("Control") = NewCustomGenericCellRenderer(Me.gridControl1,Me.gridControl1.CellModels("Control"))
Public Class CustomGenericCellRenderer
Inherits GridGenericControlCellRenderer
Public Sub New(ByVal grid As GridControlBase,ByVal model As GridCellModelBase)
MyBase.New(grid, model)
End Sub
Private bounds As Rectangle = Rectangle.Empty
Private rControl As Control = Nothing
Protected Overrides Sub OnDraw(ByVal g AsGraphics, ByVal clientRectangle As Rectangle, ByValrowIndex As Integer, ByVal colIndex As Integer, ByValstyle As GridStyleInfo)
If Me.Grid.PrintingMode Then
Me.Grid.PrintingMode = False
MyBase.OnDraw(g, clientRectangle, rowIndex, colIndex, style)
Me.Grid.PrintingMode = True
End If
Else
MyBase.OnDraw(g, clientRectangle, rowIndex, colIndex, style)
End If
End Sub
End Class |
Regards,
Mohanraj G
BS
BEPPE SALVADERI
July 15, 2018 07:36 AM UTC
Hi Mohanraj,
the sample work perfectly!
But I would need only one image on one page. It's possible?
Many thanks.
Beppe
MG
Mohanraj Gunasekaran
Syncfusion Team
July 16, 2018 12:07 PM UTC
Hi Beppe,
Thanks for your update.
Previously we have provided the sample to create the image based on displaying row count basis. So, we have suggested to export the grid to pdf then convert the pdf to image.
If you want to export all the grid rows in a single page, you can draw the grid in BitMap graphics using DrawGrid method. Please refer to the below code example and the sample. Hope this will meet your scenario and please let us know if you have any concerns.
Code example
|
Dim gridHeight As Integer = Me.gridControl1.Model.RowHeights.GetTotal(0, Me.gridControl1.Model.RowCount)
Dim gridWidth As Integer = Me.gridControl1.Model.ColWidths.GetTotal(0, Me.gridControl1.Model.ColCount)
Dim bmp As Bitmap = New Bitmap(gridWidth, gridHeight)
Dim graphics As Graphics = Graphics.FromImage(bmp)
Me.gridControl1.SuspendLayout()
Me.gridControl1.GridBounds = New Rectangle(0, 0, gridWidth, gridHeight)
'To draw the Grid in bitmap graphics.
Me.gridControl1.DrawGrid(graphics)
bmp.Save("GridControl.png")
Me.gridControl1.ResetGridBounds()
Me.gridControl1.ResumeLayout()
graphics.Dispose() |
Sample link: GridControl
Regards,
Mohanraj G
BS
BEPPE SALVADERI
July 17, 2018 06:25 PM UTC
Hi Mohanraj,
this is exactly what I need!
Many many thanks.
Beppe
MG
Mohanraj Gunasekaran
Syncfusion Team
July 18, 2018 03:46 AM UTC
Hi Beepe,
Thanks for your update.
We are glad to know that your reported problem has resolved.
Please let us know if you have any other queries.
Regards,
Mohanraj G
SIGN IN To post a reply.
- 9 Replies
- 2 Participants
-
BS BEPPE SALVADERI
- Jul 6, 2018 10:37 AM UTC
- Jul 18, 2018 03:46 AM UTC