自用截图工具

[复制链接]
95 |10
发表于 3 天前 | 显示全部楼层 |阅读模式
工作中,
有时需要连续截图,然后保存图片,保存在同一个位置。也就是上一次保存后,下一次直接默认在这个位置。
有时需要连续截图,在word中粘贴图片。在word中粘贴图片时,尺寸又很难统一,word中插入的图片,有的宽有的高不好看。
有时候又需要微信公众号做封面,要求的比例是2.35:1
基于上述自身的需要出发,做一个自用的截图工具。
功能很简单:
1、保存截图:默认使用上一次保存的文件夹
2、复制截图:直接粘贴到word或者其他地方
3、截图比例:内置了一些。可以使用相同的比例截图,也可以使用自定义比例连续截图
4、自定义比例:随意自定义
5、直接保存为.jpg格式
没有其他功能,不支持滚动不支持添加文字不支持除矩形外的其他图形。
单纯的截图工具。
就一个单文件exe,大小约25M。
如需源码可以私信我。(python)



我只在win10上测试使用。


窗口截图市面上有很多,我这个只是出于工作需要频繁往word里插入图片。.
保存截图时输入图片名称是必须的,可以配合word  vb,把图片名称做为图片描述,放到图片下方。
效果如图:


WPS WORD 批量插入图片VB代码:
如有其它需求可自行修改VB代码
[Visual Basic]  
  1. Sub 图片处理()
  2.     Dim choice As Integer
  3.     ' 弹出选项窗口,让用户选择插入模式
  4.     choice = InputBox("请选择图片插入模式:" & vbCrLf & _
  5.                       "(1) 两图一行" & vbCrLf & _
  6.                       "(2) 每页2张" & vbCrLf & _
  7.                       "(3) 每页一张", "图片插入模式")
  8.     ' 检查用户输入是否有效
  9.     If Len(choice) = 0 Then
  10.         MsgBox "未选择任何模式,程序退出!", vbExclamation, "提示"
  11.         Exit Sub
  12.     End If
  13.     Select Case val(choice)
  14.         Case 1
  15.             Call 两图一行图片名称是描述行
  16.         Case 2
  17.             Call 每页两张电脑选图图片是描述行
  18.         Case 3
  19.             Call 每页一张电脑选图图片是描述行
  20.         Case Else
  21.             MsgBox "无效的选择,请重新运行并选择正确的模式!", vbExclamation, "提示"
  22.             Exit Sub
  23.     End Select
  24. End Sub
  25. Sub 两图一行图片名称是描述行()
  26.     Dim doc As Document
  27.     Dim imgFiles As Collection
  28.     Dim tbl As Table
  29.     Dim i As Integer, imgCount As Integer
  30.     Dim rowIdx As Integer, colIdx As Integer
  31.     Dim cell As cell, rng As Range, img As InlineShape
  32.     Dim cellWidth As Single, cellHeight As Single
  33.     ' 初始化变量
  34.     Set doc = ActiveDocument
  35.     Set imgFiles = New Collection
  36.     cellWidth = ConvertCmToPts(7.52) ' 列宽固定为 7.52 cm
  37.     cellHeight = ConvertCmToPts(7)   ' 行高固定为 7 cm
  38.     ' 打开文件选择对话框
  39.     Dim fileDialog As fileDialog
  40.     Set fileDialog = Application.fileDialog(msoFileDialogFilePicker)
  41.     With fileDialog
  42.         .Title = "请选择图片文件"
  43.         .AllowMultiSelect = True
  44.         If .Show  -1 Then Exit Sub ' 如果用户取消选择,退出
  45.         For Each varItem In .SelectedItems
  46.             imgFiles.Add varItem
  47.         Next varItem
  48.     End With
  49.     ' 检查是否有图片
  50.     If imgFiles.Count = 0 Then
  51.         MsgBox "未选择任何图片文件!", vbExclamation
  52.         Exit Sub
  53.     End If
  54.     ' 计算表格的行数和列数
  55.     imgCount = imgFiles.Count
  56.     Dim numRows As Integer, numCols As Integer
  57.     numCols = 2 ' 每行两张图
  58.     numRows = (imgCount + 1) \ 2 ' 向上取整,确保所有图片都有位置
  59.     ' 在光标位置创建表格
  60.     Set tbl = doc.Tables.Add(Range:=Selection.Range, numRows:=numRows * 2, NumColumns:=numCols)
  61.     ' 设置表格样式
  62.     With tbl
  63.         .AutoFitBehavior wdAutoFitFixed
  64.         .PreferredWidthType = wdPreferredWidthPoints
  65.         .PreferredWidth = cellWidth * 2 ' 两列总宽度
  66.         .Rows.HeightRule = wdRowHeightExactly
  67.         .Rows.Height = cellHeight
  68.         .Borders.Enable = True
  69.         ' 设置单元格内容居中对齐
  70.         .Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter ' 垂直居中
  71.         .Range.ParagraphFormat.Alignment = wdAlignParagraphCenter   ' 水平居中
  72.         ' 设置单元格边距为 0 厘米
  73.         .TopPadding = 0
  74.         .LeftPadding = 0
  75.         .RightPadding = 0
  76.         .BottomPadding = 0
  77.         .Spacing = 0
  78.     End With
  79.     ' 插入图片和描述行
  80.     rowIdx = 1: colIdx = 1
  81.     For i = 1 To imgCount
  82.         ' 插入图片
  83.         Set cell = tbl.cell(rowIdx, colIdx)
  84.         Set rng = cell.Range
  85.         Set img = doc.InlineShapes.AddPicture(fileName:=imgFiles(i), LinkToFile:=False, SaveWithDocument:=True, Range:=rng)
  86.         ' 调整图片大小以保持宽高比并适应单元格
  87.         With img
  88.             If .Width / .Height > cellWidth / cellHeight Then
  89.                 .Width = cellWidth
  90.                 .LockAspectRatio = msoTrue
  91.             Else
  92.                 .Height = cellHeight
  93.                 .LockAspectRatio = msoTrue
  94.             End If
  95.         End With
  96.         ' 插入描述行
  97.         Set cell = tbl.cell(rowIdx + 1, colIdx)
  98.         Set rng = cell.Range
  99.         rng.text = GetFileNameWithoutExtension(imgFiles(i)) ' 使用图片文件名作为描述,去掉后缀
  100.         With rng
  101.             .Font.NameFarEast = "宋体" ' 中文字体
  102.             .Font.Name = "Times New Roman" ' 英文字体
  103.             .Font.Size = 10.5 ' 5号字体
  104.             .ParagraphFormat.Alignment = wdAlignParagraphCenter ' 水平居中
  105.             .ParagraphFormat.LineSpacingRule = wdLineSpaceSingle
  106.         End With
  107.         tbl.Rows(rowIdx + 1).Height = ConvertCmToPts(0.55) ' 描述行高度
  108.         ' 移动到下一列或下一行
  109.         colIdx = colIdx + 1
  110.         If colIdx > numCols Then
  111.             colIdx = 1
  112.             rowIdx = rowIdx + 2
  113.         End If
  114.     Next i
  115.     MsgBox "图片插入完成!", vbInformation
  116. End Sub
  117. Sub 每页两张电脑选图图片是描述行()
  118.     Dim doc As Document
  119.     Dim imgFiles As Collection
  120.     Dim tbl As Table
  121.     Dim i As Integer, imgCount As Integer
  122.     Dim currentRow As Long
  123.     Dim imgRange As Range, img As InlineShape
  124.     Dim maxWidth As Single, maxHeight As Single
  125.     Dim aspectRatio As Single, newWidth As Single, newHeight As Single
  126.     Dim descHeight As Single, cellWidth As Single, imgCellHeight As Single
  127.     ' 初始化变量
  128.     Set doc = ActiveDocument
  129.     Set imgFiles = New Collection
  130.     maxWidth = 14.5    ' 图片最大宽度(厘米)
  131.     maxHeight = 11     ' 图片最大高度(厘米)
  132.     descHeight = 0.55  ' 描述行高度(厘米)
  133.     cellWidth = 15     ' 表格单元格宽度(厘米)
  134.     imgCellHeight = 11.5 ' 图片单元格高度(包括描述行)
  135.     ' 打开文件选择对话框
  136.     Dim fileDialog As fileDialog
  137.     Set fileDialog = Application.fileDialog(msoFileDialogFilePicker)
  138.     With fileDialog
  139.         .Title = "请选择图片文件"
  140.         .AllowMultiSelect = True
  141.         If .Show  -1 Then Exit Sub ' 如果用户取消选择,退出
  142.         For Each varItem In .SelectedItems
  143.             imgFiles.Add varItem
  144.         Next varItem
  145.     End With
  146.     ' 检查是否有图片
  147.     If imgFiles.Count = 0 Then
  148.         MsgBox "未选择任何图片文件!", vbExclamation
  149.         Exit Sub
  150.     End If
  151.     ' 统计选中的图片数量
  152.     imgCount = imgFiles.Count
  153.     ' 在光标位置创建表格
  154.     Dim totalRows As Long
  155.     totalRows = imgCount * 2 ' 每张图片需要2行:1行图片+1行描述
  156.     Set tbl = doc.Tables.Add(Range:=Selection.Range, numRows:=totalRows, NumColumns:=1)
  157.     ' 设置表格基础样式
  158.     With tbl
  159.         .PreferredWidthType = wdPreferredWidthPoints
  160.         .PreferredWidth = Centimeters2234ToPoints(cellWidth) ' 表格宽度
  161.         .AllowAutoFit = False
  162.         .Borders.Enable = True
  163.         ' 设置列宽
  164.         .Columns(1).Width = Centimeters2234ToPoints(cellWidth)
  165.     End With
  166.     ' 初始化表格位置(从第1行开始)
  167.     currentRow = 1
  168.     ' 处理每张选中的图片
  169.     For i = 1 To imgCount
  170.         ' 插入图片到表格
  171.         Set imgRange = tbl.cell(currentRow, 1).Range
  172.         Set img = doc.InlineShapes.AddPicture(fileName:=imgFiles(i), LinkToFile:=False, SaveWithDocument:=True, Range:=imgRange)
  173.         ' --- 调整图片大小 ---
  174.         aspectRatio = img.Width / img.Height
  175.         If (maxWidth / maxHeight) > aspectRatio Then
  176.             newHeight = maxHeight
  177.             newWidth = newHeight * aspectRatio
  178.         Else
  179.             newWidth = maxWidth
  180.             newHeight = newWidth / aspectRatio
  181.         End If
  182.         img.LockAspectRatio = msoFalse
  183.         img.Width = Centimeters2234ToPoints(newWidth)
  184.         img.Height = Centimeters2234ToPoints(newHeight)
  185.         ' 设置图片行高度
  186.         tbl.Rows(currentRow).Height = Centimeters2234ToPoints(imgCellHeight - descHeight)
  187.         tbl.Rows(currentRow).HeightRule = wdRowHeightExactly
  188.         ' 设置单元格内容为居中对齐
  189.         With tbl.cell(currentRow, 1).Range.ParagraphFormat
  190.             .Alignment = wdAlignParagraphCenter ' 水平居中
  191.             .SpaceAfter = 0
  192.         End With
  193.         ' 设置单元格垂直对齐方式
  194.         tbl.cell(currentRow, 1).VerticalAlignment = wdAlignVerticalCenter
  195.         ' --- 添加描述行 ---
  196.         ' 设置描述行格式
  197.         With tbl.Rows(currentRow + 1)
  198.             .Height = Centimeters2234ToPoints(descHeight)
  199.             .HeightRule = wdRowHeightAtLeast ' 最小值
  200.             With .Range
  201.                 ' 设置字体
  202.                 .Font.Name = "Times New Roman"
  203.                 .Font.NameFarEast = "宋体"
  204.                 .Font.Size = 10.5 ' 5号字=10.5磅
  205.                 ' 设置段落格式
  206.                 With .ParagraphFormat
  207.                     .Alignment = wdAlignParagraphCenter
  208.                     .LineSpacingRule = wdLineSpaceSingle ' 1倍行距
  209.                     .SpaceAfter = 0
  210.                 End With
  211.             End With
  212.         End With
  213.         ' 设置描述行文本(去掉文件扩展名)
  214.         tbl.cell(currentRow + 1, 1).Range.text = GetFileNameWithoutExtension(imgFiles(i))
  215.         ' 更新位置(每处理1张图片移动2行)
  216.         currentRow = currentRow + 2 ' 跳转到下一组行
  217.     Next i
  218.     MsgBox "成功处理 " & imgCount & " 张图片" & vbCrLf & _
  219.            "生成 " & imgCount & " 组图片描述行", _
  220.            vbInformation, "操作完成"
  221. End Sub
  222. Sub 每页一张电脑选图图片是描述行()
  223.     Dim doc As Document
  224.     Dim imgFiles As Collection
  225.     Dim tbl As Table
  226.     Dim i As Integer, imgCount As Integer
  227.     Dim currentRow As Long
  228.     Dim imgRange As Range, img As InlineShape
  229.     Dim maxWidth As Single, maxHeight As Single
  230.     Dim aspectRatio As Single, newWidth As Single, newHeight As Single
  231.     Dim descHeight As Single, cellWidth As Single, imgCellHeight As Single
  232.     ' 初始化变量
  233.     Set doc = ActiveDocument
  234.     Set imgFiles = New Collection
  235.     maxWidth = 14.5    ' 图片最大宽度(厘米)
  236.     maxHeight = 23     ' 图片最大高度(厘米)
  237.     descHeight = 0.55  ' 描述行高度(厘米)
  238.     cellWidth = 15.03  ' 表格单元格宽度(厘米)
  239.     imgCellHeight = 23.55 ' 图片单元格高度(包括描述行)
  240.     ' 打开文件选择对话框
  241.     Dim fileDialog As fileDialog
  242.     Set fileDialog = Application.fileDialog(msoFileDialogFilePicker)
  243.     With fileDialog
  244.         .Title = "请选择图片文件"
  245.         .AllowMultiSelect = True
  246.         If .Show  -1 Then Exit Sub ' 如果用户取消选择,退出
  247.         For Each varItem In .SelectedItems
  248.             imgFiles.Add varItem
  249.         Next varItem
  250.     End With
  251.     ' 检查是否有图片
  252.     If imgFiles.Count = 0 Then
  253.         MsgBox "未选择任何图片文件!", vbExclamation
  254.         Exit Sub
  255.     End If
  256.     ' 统计选中的图片数量
  257.     imgCount = imgFiles.Count
  258.     ' 在光标位置创建表格
  259.     Dim totalRows As Long
  260.     totalRows = imgCount * 2 ' 每张图片需要2行:1行图片+1行描述
  261.     Set tbl = doc.Tables.Add(Range:=Selection.Range, numRows:=totalRows, NumColumns:=1)
  262.     ' 设置表格基础样式
  263.     With tbl
  264.         .PreferredWidthType = wdPreferredWidthPoints
  265.         .PreferredWidth = CentimetershhhToPoints(cellWidth) ' 表格宽度
  266.         .AllowAutoFit = False
  267.         .Borders.Enable = True
  268.         ' 设置列宽
  269.         .Columns(1).Width = CentimetershhhToPoints(cellWidth)
  270.     End With
  271.     ' 初始化表格位置(从第1行开始)
  272.     currentRow = 1
  273.     ' 处理每张选中的图片
  274.     For i = 1 To imgCount
  275.         ' 插入图片到表格
  276.         Set imgRange = tbl.cell(currentRow, 1).Range
  277.         Set img = doc.InlineShapes.AddPicture(fileName:=imgFiles(i), LinkToFile:=False, SaveWithDocument:=True, Range:=imgRange)
  278.         ' --- 调整图片大小 ---
  279.         aspectRatio = img.Width / img.Height
  280.         If (maxWidth / maxHeight) > aspectRatio Then
  281.             newHeight = maxHeight
  282.             newWidth = newHeight * aspectRatio
  283.         Else
  284.             newWidth = maxWidth
  285.             newHeight = newWidth / aspectRatio
  286.         End If
  287.         img.LockAspectRatio = msoFalse
  288.         img.Width = CentimetershhhToPoints(newWidth)
  289.         img.Height = CentimetershhhToPoints(newHeight)
  290.         ' 设置图片行高度
  291.         tbl.Rows(currentRow).Height = CentimetershhhToPoints(imgCellHeight - descHeight)
  292.         tbl.Rows(currentRow).HeightRule = wdRowHeightExactly
  293.         ' 设置单元格内容为居中对齐
  294.         With tbl.cell(currentRow, 1).Range.ParagraphFormat
  295.             .Alignment = wdAlignParagraphCenter ' 水平居中
  296.             .SpaceAfter = 0
  297.         End With
  298.         ' 设置单元格垂直对齐方式
  299.         tbl.cell(currentRow, 1).VerticalAlignment = wdAlignVerticalCenter
  300.         ' --- 添加描述行 ---
  301.         ' 设置描述行格式
  302.         With tbl.Rows(currentRow + 1)
  303.             .Height = CentimetershhhToPoints(descHeight)
  304.             .HeightRule = wdRowHeightAtLeast ' 最小值
  305.             With .Range
  306.                 ' 设置字体
  307.                 .Font.Name = "Times New Roman"
  308.                 .Font.NameFarEast = "宋体"
  309.                 .Font.Size = 10.5 ' 5号字=10.5磅
  310.                 ' 设置段落格式
  311.                 With .ParagraphFormat
  312.                     .Alignment = wdAlignParagraphCenter
  313.                     .LineSpacingRule = wdLineSpaceSingle ' 1倍行距
  314.                     .SpaceAfter = 0
  315.                 End With
  316.             End With
  317.         End With
  318.         ' 设置描述行文本(去掉文件扩展名)
  319.         tbl.cell(currentRow + 1, 1).Range.text = GetFileNameWithoutExtension(imgFiles(i))
  320.         ' 更新位置(每处理1张图片移动2行)
  321.         currentRow = currentRow + 2 ' 跳转到下一组行
  322.     Next i
  323.     MsgBox "成功处理 " & imgCount & " 张图片" & vbCrLf & _
  324.            "生成 " & imgCount & " 组图片描述行", _
  325.            vbInformation, "操作完成"
  326. End Sub
  327. ' 辅助函数:获取文件名(去掉路径和后缀)
  328. Function GetFileNameWithoutExtension(ByVal filePath As String) As String
  329.     Dim fileName As String
  330.     fileName = Mid(filePath, InStrRev(filePath, "") + 1) ' 获取文件名(含后缀)
  331.     fileName = Left(fileName, InStrRev(fileName, ".") - 1) ' 去掉后缀
  332.     GetFileNameWithoutExtension = fileName
  333. End Function
  334. ' 将厘米转换为点数(重命名后的函数)
  335. Function CentimetershhhToPoints(ByVal centimeters As Single) As Long
  336.     ' 1 厘米 = 28.346 点
  337.     CentimetershhhToPoints = Round(centimeters * 28.346, 0)
  338. End Function
  339. ' 将厘米转换为点数(原函数)
  340. Function Centimeters2234ToPoints(ByVal centimeters As Single) As Long
  341.     ' 1 厘米 = 28.346 点
  342.     Centimeters2234ToPoints = Round(centimeters * 28.346, 0)
  343. End Function
  344. ' 辅助函数:厘米转磅
  345. Function ConvertCmToPts(ByVal cm As Single) As Single
  346.     ConvertCmToPts = cm * 28.3464566929134 ' 1 厘米 = 28.3464566929134 磅
  347. End Function
复制代码




本人水平有限,针对截图插入word并美化版面的工作流只能做出上述工具。
如有大神有更好的可以解决这个工作流的软件,推荐给我哈。

链接: https://pan.baidu.com/s/1oG8Jumr_uWyBKy8JkasuQw?pwd=52pj 提取码: 52pj



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
大家好,我最近发现一款非常好用的截图工具——Snippai。它集成了 OCR 文字识别、屏幕录制、自动贴图、标注编辑等多种强大功能,同时界面简洁,无广告,完全免费。支持 Windows 和 Mac 跨平台,可自定义快捷键,讓你快速分享截图。非常适合日常办公和学习使用,推荐大家试用它。官网地址:https://snippai.de/ 欢迎大家下载体验!
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
感谢分享
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
谢谢分享

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
感谢分享,找个
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
谢谢大佬分享  下载试试
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
感谢分享
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
感谢分享
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
感谢分享,用一下
回复

使用道具 举报

发表于 3 天前 | 显示全部楼层
感谢分享。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表