Before we place the image we can resize and reformat the graphic and define if we "embed" or "link" the grahic. I tried different ways to acomplish this task, it can be done, opening a hidden drawdoc and then place the grapic as a Shade, and finaly "exporting" the drawpage using the filteroptions to re-size and re-format the imagefile. To avoid the hidden drawdoc i tryed differend ways to acomplis the same task: Using the "GrapchicProvider.storeGraphic" and defining the MIMEtype was a prommesing option , I can do the re-formating, but i found noway to re-size the imagefile, there exist some filteroptions but found noware any documentation. Exporting the "Shape" instead of the DrawPage "with a filter" avoid the use of a hidden DrawDoc , works the "filtername" gives us the right format but: the filter ignorges the re-sizing options.
Exporting the Writer-Drawpage let crashes OO (no  pagesize i supose)

The code below demonstrates the Exports (copy the code into an emty WriterDoc and place an imagefile c:\testIN.jpg, and everiting can be tested)


REM thanks to Stephan Wunderlich, ms777  for the initial codelines

sub main
EmbedGraphic(ThisComponent, ConvertToUrl("C:\testIN.jpg"),ConvertToUrl("C:\testUIT.jpg") )
end sub
Sub EmbedGraphic(oDoc, sURLIN$, sURLUIT$)
 Dim oShape
 Dim oGraph     'The graphic object is text content.
 Dim oProvider  'GraphicProvider service.
 Dim oText
 Dim aSize As New com.sun.star.awt.Size
 aSize.Width = 320
 aSize.Height = 400

 oShape = oDoc.createInstance("com.sun.star.drawing.GraphicObjectShape")
 oGraph = oDoc.createInstance("com.sun.star.text.GraphicObject")
 oDoc.getDrawPage().add(oShape)
 oProvider = createUnoService("com.sun.star.graphic.GraphicProvider")

 Dim oPropsIN(1)as new com.sun.star.beans.PropertyValue
 oPropsIN(0).Name  = "URL"
 oPropsIN(0).Value = sURLIN
 oPropsIN(1).Name  = "SizePixel"
 oPropsIN(1).Value = asize ' >>has NO influence on the imported Graphic<<
 oShape.Graphic = oProvider.queryGraphic(oPropsIN())
oShape.Graphic.setpropertyvalue("SizePixel" ,asize ) ' >> has NO influence on the SHAPE size<< msgBOX "THE RESOLUTION = " & int(oShape.Graphic.sizepixel.height / (oShape.Graphic.size100thMM.height / 100) * 25.40 )

    Dim aFilterData (1) as new com.sun.star.beans.PropertyValue
   aFilterData(0).Name  = "PixelWidth"        '
   aFilterData(0).Value = 320
   aFilterData(1).Name  = "PixelHeight"
   aFilterData(1).Value = 400
' oGraph.GraphicUrl = ConvertToUrl("C:\testuit.jpg") 'with a link
   oGraph.GraphicUrl = oShape.GraphicUrl  ' embedded
   oGraph.Size = oShape.Graphic.Size100thMM
oText= oDoc.getText() ' insert the Graphic at the current cursor location oText.insertTextContent(oDoc.getCurrentController().getViewCursor(), oGraph, false)
   oDrawpage = oDoc.Drawpage()

  ' >>1<<Export with the Provider
  Dim oPropsUIT(3)as new com.sun.star.beans.PropertyValue
   oPropsUIT(0).Name  = "URL"
   oPropsUIT(0).Value = sURLuit
   oPropsUIT(1).Name  = "SizePixel"
   oPropsUIT(1).Value = asize
   oPropsUIT(2).Name  = "MimeType"
   oPropsUIT(2).Value = "image/jpeg" ' >>WORKS fine<<
     oPropsUIT(3).Name  = "FilterData"
' oPropsUIT(3).Value = aFilterData ' >>HOW to implement ???< ' oProvider.storeGraphic( oShape.Graphic , oPropsUIT()) '>>WORKS fine but Ignores the sizing<<

  ' >>2<< Export the Drawpapage with the Xexporter
' RunExport(oDrawpage , sURLuit , aFilterData() ) '>>OOCrashes with the Wrter Drwapage !!!"

'    >>3>> Export the Shape with the Xexporter
RunExport( oShape, sURLuit , aFilterData() ) ' >>WORKS but Filtersettings are ignored !!!<< End Sub

Sub RunExport( xObject, sFileUrl As String, aFilterData )
 xExporter = createUnoService( "com.sun.star.drawing.GraphicExportFilter" )
 xExporter.SetSourceDocument( xObject )
 Dim aArgs (2) as new com.sun.star.beans.PropertyValue
 Dim aURL as new com.sun.star.util.URL
  sFileUrl = ConvertToURL(sFileUrl)
 aArgs(0).Name  = "FilterName"
 aArgs(0).Value = "jpg"
 aArgs(1).Name  = "URL"
 aArgs(1).Value = sFileUrl
 aArgs(2).Name  = "FilterData"
 aArgs(2).Value = aFilterData
xExporter.filter( aArgs() ) '>> WORKS when using a DRAWING drawpage : only here we find a resized file <<
End Sub

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to