Hi Andreas, Stephan, *

Stephan Wunderlich escribió:
Hi Andreas,

in openoffice it is possible to import EMF images.
Can anyone please tell me if API functions are available to load a EMF
file and convert it to a bitmap format ( BMP, TIF ).

This should possibly work on linux too.


the following Basic sample should do what you want ...

------------------
rem to be adjusted
source = "<fileurl to your emf file>"
aURL.complete = "<fileurl for the tiff file>"

emffile = StarDesktop.loadComponentFromURL(source,0,"_blank",dimArray())

xExporter = createUnoService( "com.sun.star.drawing.GraphicExportFilter" )
xExporter.SetSourceDocument( emffile.currentController.currentPage )

this will

1. open the image in Draw, leaving it in the center
2. export the *whole* page, including margins

so, in order to really export *only* the image, the code should be:

Dim oDrawPage as Object
Dim oPic as Object
oDrawPage = emffile.getDrawPages().getByIndex(0)
oPic = oDrawPage.getByIndex(0)
xExporter.SetSourceDocument( oPic )


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

aArgs(0).Name  = "MediaType"
aArgs(0).Value = "image/tiff"
aArgs(1).Name  = "URL"
aArgs(1).Value = aURL
xExporter.filter( aArgs() )
emffile.close(true)
------------------


But IMHO loading the image is a waste of resources, better use
com.sun.star.graphic.GraphicProvider

[fix line breaks if copy and paste!]
'*****************************************************************
Sub storeGraphic(sLocationURL$, sTargetURL$, sMimeType$, Optional
aFilterData() as Object)

        Dim oGraphicProvider as Object, oGraphic as Object
        
        oGraphicProvider = 
createUnoService("com.sun.star.graphic.GraphicProvider")
        
        Dim aInputMediaProperties (0)as new com.sun.star.beans.PropertyValue
        aInputMediaProperties(0).Name  = "URL"
        aInputMediaProperties(0).Value = sLocationURL
        
        oGraphic = oGraphicProvider.queryGraphic(aInputMediaProperties())       
        
        Dim aOutputMediaProperties (1) as new com.sun.star.beans.PropertyValue
        aOutputMediaProperties(0).Name  = "URL"
        aOutputMediaProperties(0).Value = sTargetURL
        aOutputMediaProperties(1).Name  = "MimeType"
        aOutputMediaProperties(1).Value = sMimeType
        
        If NOT IsMissing( aFilterData ) Then
                If UBound( aFilterData ) >= 0 Then
                        Dim n%
                        n = UBound(aOutputMediaProperties)+1
                        ReDim Preserve aOutputMediaProperties( n )
                        aOutputMediaProperties(n).Name = "FilterData"
                        aOutputMediaProperties(n).Value = aFilterData
                End If
        End If
        
        oGraphicProvider.storeGraphic(oGraphic, aOutputMediaProperties)

End Sub
'*****************************************************************


Two ways to use this Sub [change the URLs of course!]:


'*******************************************************************
Sub Test_PNG_to_JPEG_with_FilterData

        Dim aFilterData (1) as new com.sun.star.beans.PropertyValue
        aFilterData(0).Name  = "Quality"
        aFilterData(0).Value = 100
        aFilterData(1).Name  = "ColorMode"
        aFilterData(1).Value = 1 ': Grayscale
        
        'Defaults are
        'ColorMode = 0
        'Quality = 75
        
        storeGraphic(_
                convertToURL("/home/ariel/Imágenes/Ariel.png"), _
                convertToURL("/home/ariel/Imágenes/Ariel.jpg"), _
                "image/jpeg", aFilterData)

End Sub


Sub Test_WMF_to_tiff

        storeGraphic(_
                convertToURL("/home/ariel/Imágenes/Ariel.wmf"), _
                convertToURL("/home/ariel/Imágenes/Ariel.tiff"), _
                "image/tiff", Array())

End Sub
'*******************************************************************


See
http://api.openoffice.org/docs/common/ref/com/sun/star/graphic/XGraphicProvider.html
http://api.openoffice.org/docs/common/ref/com/sun/star/graphic/MediaProperties.html

Supported mime-types are listed on
http://api.openoffice.org/docs/common/ref/com/sun/star/graphic/MediaProperties.html#MimeType

FilterData is "documented" in
[/opt/openoffice.org2.4]/share/registry/schema/org/openoffice/Office/Common.xcs,
node-path /org.openoffice.Office.Common/Filter/Graphic/Export


Regards
Ariel.


--
Ariel Constenla-Haile
La Plata, Argentina

[EMAIL PROTECTED]
[EMAIL PROTECTED]

http://www.ArielConstenlaHaile.com.ar/ooo/



"Aus der Kriegsschule des Lebens
                - Was mich nicht umbringt,
        macht mich härter."
                Nietzsche Götzendämmerung, Sprüche und Pfeile, 8.

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

Reply via email to