Laurent Godard wrote:
Hi all
in java
i want to import a graphic in a draw document
seems to work but the only problem is that it is 100 height & width,
no matter the original size
how can i have my image imported with the correct proportion & size so
that i can select it (to export it)
here is a snippet of where i am
(thx to cloph :) )
could someone put me in the right direction ?
thanks in advance
Laurent
java i do not understand but with basic you can do it als folows
oSelections = oDoc.getCurrentSelection
if
oselections.supportsService("com.sun.star.text.TextGraphicObject") then
oGraphic = oSelections
sGraphicUrl = oGraphic.Graphicurl
' On Local Error GoTo EERSTSAVEN
If InStr(1, sGraphicURL, "vnd.sun.star.GraphicObject:", 0) = 1 Then
' get the picture name (comes without the extension)
sGraphicURL = Mid(sGraphicURL, 28, Len(sGraphicURL))
' so search all files in pictures folder for the current
picture ...
For j = 0 to oGraphics.getcount-1
If InStr(1, mFiles(j), sGraphicURL, 0) Then
' create new name with extension ...
sGraphicName = oGraphic.getName() & Mid(mFiles(j),
Len(sGraphicURL)+1, Len(mFiles(j))
oPreviewGraph =
getGraphFromStream(oPictures.getByName(mFiles(j)).getInputStream())
exit for
else
end if
next
else
oPreviewGraph = getGraphFromUrl(sGraphicUrl)
endif
if opreviewgraph.gettype = 1 then
sFileType = "Raster"
else
sFileType = "Vector"
end if
if sFileType = "Raster" then
If oPreviewGraph.size100thMM.height = 0 Then
iResolution = 96
Else
iResolution = int(oPreviewGraph.sizepixel.height /
(oPreviewGraph.size100thMM.height / 100) * 25.40 )
if iResolution = 0 then
Iresolution = 254
endif
endif
else
iResolution = 96
iMMh = oPreviewGraph.size100thMM.height
iMMw = oPreviewGraph.size100thMM.width
end if
acrop = oGraphic.GetPropertyValue("GraphicCrop")
iFotW = oGraphic.width'
iFotH = oGraphic.height'
iMMh = int(oPreviewGraph.size100thMM.height )
if immH = 0 then
immH = int((oPreviewGraph.sizePixel.height/iRresolution) * 25.40)
endif
iMMw = int(oPreviewGraph.size100thMM.width)
if immw = 0 then
immw = int((oPreviewGraph.sizePixel.width/iRresolution) * 25.40)
endif
'----------------------------------------------------------------------------------------------------
function getGraphFromUrl(sFileUrl as String) as Object
oProvider = createUnoService("com.sun.star.graphic.GraphicProvider")
Dim oPropsIN(0)as new com.sun.star.beans.PropertyValue
oPropsIN(0).Name = "URL"
oPropsIN(0).Value = sFileUrl
getGraphFromUrl = oProvider.queryGraphic(oPropsIN())
end function
'-------------------------------------------------------------------
function getGraphFromStream(oInputStream as Object) as Object
oProvider = createUnoService("com.sun.star.graphic.GraphicProvider")
Dim oPropsIN(0)as new com.sun.star.beans.PropertyValue
oPropsIN(0).Name = "InputStream"
oPropsIN(0).Value = oInputStream
getGraphFromStream = oProvider.queryGraphic(oPropsIN())
end function
hope it helps
Fernand
'------------------
XMultiServiceFactory xFactory =
(XMultiServiceFactory)UnoRuntime.queryInterface(
XMultiServiceFactory.class, document);
Object image =
xFactory.createInstance("com.sun.star.drawing.GraphicObjectShape");
XShape graphicShape = (XShape)
UnoRuntime.queryInterface(XShape.class, image);
XNameContainer xBitmapContainer = null;
xBitmapContainer = (XNameContainer) UnoRuntime.queryInterface(
XNameContainer.class, xFactory.createInstance(
"com.sun.star.drawing.BitmapTable"));
xBitmapContainer.insertByName("someID", inputUrl);
String internalURL = AnyConverter.toString(xBitmapContainer
.getByName("someID"));
XPropertySet props =
(XPropertySet)UnoRuntime.queryInterface(XPropertySet.class,
graphicShape);
props.setPropertyValue("GraphicURL",internalURL );
// add it to the document first drawpage
XDrawPagesSupplier xDrawPagesSupplier =
(XDrawPagesSupplier)UnoRuntime.queryInterface(
XDrawPagesSupplier.class,
document);
XDrawPages xDrawPages = xDrawPagesSupplier.getDrawPages();
Object objDrawPage = xDrawPages.getByIndex(0);
XDrawPage drawpage = (XDrawPage)
UnoRuntime.queryInterface(XDrawPage.class, objDrawPage);
drawpage.add(graphicShape);
refreshDocument(document);
Object objShape = drawpage.getByIndex(0);
XShape finalShape = (XShape)
UnoRuntime.queryInterface(XShape.class, objShape);
Size currentSize = finalShape.getSize();
// width & height = 100
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]