OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

How to convert a chart to Image in C#

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
katahlyn
Newbie
Newbie


Joined: 20 Dec 2006
Posts: 4

PostPosted: Wed Dec 20, 2006 4:41 am    Post subject: How to convert a chart to Image in C# Reply with quote

Code:

public System.Drawing.Image GetImageDataFromChartDocument(XChartDocument chart)
{
  unoidl.com.sun.star.datatransfer.XTransferable xTransfer = (unoidl.com.sun.star.datatransfer.XTransferable)chart;

  unoidl.com.sun.star.datatransfer.DataFlavor df = new unoidl.com.sun.star.datatransfer.DataFlavor("image/png", "PNG", typeof(Byte[]));
  byte[] imageData = (byte[])xTransfer.getTransferData(df).Value;

  MemoryStream ms = new MemoryStream(imageData);

  System.Drawing.Image img = System.Drawing.Image.FromStream(ms);

  ms.Dispose();

  return img;
}

Now the problem with this, is that the size of the image is always 302x200 or something like that. If anyone knows how to get the image to match the size of the chart, I would really apreciated.
Also I'm looking for a way to convert an Image to XShape, but couldn't find any, yet. Inserting in the spreadsheet through clipboard is not an option (multithreading issues + not to mention the fact that the clipboard is shared between processes). And for now I do that using a temporary file, but I don't think the API is that limited.
_________________
Asyncronously daydreaming...
Back to top
View user's profile Send private message Yahoo Messenger
ms777
Super User
Super User


Joined: 07 Feb 2004
Posts: 1355

PostPosted: Thu Dec 21, 2006 1:46 pm    Post subject: Reply with quote

in Basic see http://codesnippets.services.openoffice.org/Office/Office.GraphicExport.snip or take this here:
Code:

Sub ExportCurrentPageOrSelection
'taken from http://codesnippets.services.openoffice.org/Office/Office.GraphicExport.snip
'with minor modifications from ms777

'creating filter dependent filter properties
Dim aFilterData (2) as new com.sun.star.beans.PropertyValue
aFilterData(0).Name  = "PixelWidth"        '
aFilterData(0).Value = 2000
aFilterData(1).Name  = "PixelHeight"
aFilterData(1).Value = 1000
aFilterData(2).Name  ="Quality"
aFilterData(2).Value = 80
Dim sFileUrl As String
sFileUrl = "file:///c:/test_export.jpg"

Dim aArgs (2) as new com.sun.star.beans.PropertyValue
Dim aURL as new com.sun.star.util.URL

aURL.complete = sFileUrl
aArgs(0).Name  = "MediaType"
aArgs(0).Value = "image/jpeg"
aArgs(1).Name  = "URL"
aArgs(1).Value = aURL
aArgs(2).Name  = "FilterData"
aArgs(2).Value = aFilterData()

xDoc = thiscomponent
xView = xDoc.currentController
xSelection = xView.selection
If isEmpty( xSelection ) then
  xObject = xView.currentPage
  else
  xObject = xSelection
  End If

xExporter = createUnoService( "com.sun.star.drawing.GraphicExportFilter" )
xExporter.SetSourceDocument( xObject )

xExporter.filter( aArgs() )
End Sub
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group