List Info

Thread: Draw imported graphic size




Draw imported graphic size
user name
2007-07-12 11:19:08
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

'------------------

   XMultiServiceFactory xFactory = 
(XMultiServiceFactory)UnoRuntime.queryInterface( 
                          XMultiServiceFactory.class,
document);

         Object image = 
xFactory.createInstance("com.sun.star.drawing.GraphicOb
jectShape");

         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


-- 
Laurent Godard <lgodardindesko.com> -
Ingénierie OpenOffice.org - 
http://www.indesko.com
Nuxeo Enterprise Content Management >> http://www.nuxeo.com - 
http://www.nuxeo.org
Livre "Programmation OpenOffice.org", Eyrolles
2004-2006

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: Draw imported graphic size
user name
2007-07-12 11:52:36
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.TextGrap
hicObject") 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)).getInputSt
ream())

        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&
quot;)
  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&
quot;)
  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.GraphicOb
jectShape");
>
>         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: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


Re: Draw imported graphic size
user name
2007-07-18 02:08:23
Hi Fernand

>> Laurent
> java i do not understand but with basic you can do it
als folows
>

thanks a lot
i'll have a look asap

maybe could you please send me the code as attachment as it
is 
completely unreadable in this mail

but what a pain regarding the api !!
I really think should be a direct api to be used

Thanks again, i let you know

Laurent

-- 
Laurent Godard <lgodardindesko.com> -
Ingénierie OpenOffice.org - 
http://www.indesko.com
Nuxeo Enterprise Content Management >> http://www.nuxeo.com - 
http://www.nuxeo.org
Livre "Programmation OpenOffice.org", Eyrolles
2004-2006

------------------------------------------------------------
---------
To unsubscribe, e-mail: dev-unsubscribeapi.openoffice.org
For additional commands, e-mail: dev-helpapi.openoffice.org


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )