使用Swift 5 xcode 13将屏幕快照另存为pdf或高分辨率图像

问题描述

在这里找到:如何在Swift中拍摄全屏截图?

func getScreenshot() -> UIImage {
    var window: UIWindow? = UIApplication.shared.keyWindow
    window = UIApplication.shared.windows[0] as? UIWindow
    UIGraphicsBeginImageContextWithOptions(window!.frame.size,window!.isOpaque,0.0)
    window!.layer.render(in: UIGraphicsGetCurrentContext()!)
    let image = UIGraphicsGetimageFromCurrentimageContext()
    UIGraphicsEndImageContext()
    return image!
}

我的图像在DIN A4格式的页面上包含大量文字。图像质量非常差,无法打印。有没有机会提高分辨率?

最好的方法是将屏幕截图另存为pdf。这里有什么帮助保存和重新引用我设备中的image.pdf。

表示任何提示

解决方法

只需通过PDFKit将图像转换为pdf

require(tidyverse)
require(shiny)
require(plotly)

ui = fluidPage(
  sidebarPanel(width = 3,sliderInput('count','count',min = 3,max = 100,value = 100,step = 25)
  ),mainPanel(width = 9,div(plotlyOutput("plot",height = '200vh'),style='height:90vh !important; overflow:auto !important; background-color:yellow;')
  )
)

server <- function(input,output,session) {
  
  output$plot = renderPlotly({
    d = data.frame(x = head(sentences,input$count),y = rlnorm(input$count,meanlog = 5))
    p = d %>% ggplot(aes(fct_reorder(x,y),y)) +
      geom_col(width = 0.1,col='grey90') + geom_point(size = 2) + 
      coord_flip() +
      theme_minimal(base_size = 12) + theme(panel.grid.major.y = element_blank())
    pltly = ggplotly(p) %>% layout(xaxis = list(side ="top" ))
    pltly$height = nrow(d) * 15
    pltly
  })
  
}

shinyApp(ui = ui,server = server,options = list(launch.browser = FALSE))