gpt4 book ai didi

libreoffice - Libre Office 宏裁剪图像

转载 作者:行者123 更新时间:2023-12-02 16:19:31 28 4
gpt4 key购买 nike

我有一个 Libre Office 宏,需要裁剪图像,但我找不到任何有用的文档或示例。有人知道如何做吗?

dim noArgs()
dim emptyDocComponent as object
dim document as object
dim dispatcher as object
emptyDocComponent = StarDesktop.LoadComponentFromUrl("private:factory/swriter", "_blank", 0, noArgs())
frame = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(3) as new com.sun.star.beans.PropertyValue
args1(0).Name = "FileName"
args1(0).Value = "file://" & inputPath
args1(1).Name = "FilterName"
args1(1).Value = "<All formats>"
args1(2).Name = "AsLink"
args1(2).Value = false
args1(3).Name = "Style"
args1(3).Value = "Graphics"

dispatcher.executeDispatch(frame, ".uno:InsertGraphic", "", 0, args1())

selection = ThisComponent.CurrentSelection
If selection.ImplementationName <> "SwXTextGraphicObject" Then
Exit Sub
End If

' this is what the macro recorder captured, but it was "rem" and non-functional
rem dispatcher.executeDispatch(document, ".uno:Crop", "", 0, Array())

*** 编辑

这是我现在正在使用的内容,以防对其他人有所帮助。我有一张已知尺寸(以像素为单位)的图片需要裁剪。不完全确定计算是否完全准确,但到目前为止它是有效的。

dim noArgs()
dim emptyDocComponent as object
dim document as object
dim dispatcher as object
emptyDocComponent = StarDesktop.LoadComponentFromUrl("private:factory/swriter", "_blank", 0, noArgs())
frame = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(3) as new com.sun.star.beans.PropertyValue
args1(0).Name = "FileName"
args1(0).Value = "file://" & inputPath
args1(1).Name = "FilterName"
args1(1).Value = "<All formats>"
args1(2).Name = "AsLink"
args1(2).Value = false
args1(3).Name = "Style"
args1(3).Value = "Graphics"

dispatcher.executeDispatch(frame, ".uno:InsertGraphic", "", 0, args1())

selection = ThisComponent.CurrentSelection
If selection.ImplementationName <> "SwXTextGraphicObject" Then
Exit Sub
End If

' size = (pixels / pixelsPerInch) * mm/in * scaling * actual graphic / displayed graphic
imageWidth = (int(pixelWidth) / int(xPixelsPerInch)) * 25.4 * 110 * (selection.actualSize.Width / selection.Width)
imageHeight = (int(pixelHeight) / int(yPixelsPerInch)) * 25.4 * 110 * (selection.actualSize.Height / selection.Height)

GraphicCrop = selection.GraphicCrop
GraphicCrop.Top = selection.actualSize.Height - imageHeight
GraphicCrop.Bottom = 0
GraphicCrop.Left = 0
GraphicCrop.Right = selection.actualSize.Width - imageWidth
selection.GraphicCrop = GraphicCrop

最佳答案

TextGraphicObject 有一个名为 GraphicCrop 的结构.

以下代码改编自https://forum.openoffice.org/en/forum/viewtopic.php?f=25&t=72496 .

selection = ThisComponent.CurrentSelection
If selection.ImplementationName <> "SwXTextGraphicObject" Then
Exit Sub
End If

pxPerInch = 100*25.6
cropFig = selection.GraphicCrop
cropFig.Left = 0.27*pxPerInch
cropFig.Right = 1.34*pxPerInch
cropFig.Top = 0.31*pxPerInch
cropFig.Bottom = 0.18*pxPerInch
selection.GraphicCrop = cropFig

关于libreoffice - Libre Office 宏裁剪图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45718985/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com