乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 116|回复: 8

VBA中的图像另存为

[复制链接]

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2006-12-13 15:52:50 | 显示全部楼层 |阅读模式
有谁知道访问图像保存的方法吗? 我使用光栅设计07,但我认为我没有任何引用集,(我接下来要检查一下)我试图将jpg文件转换为二进制tif文件

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2006-12-14 17:10:36 | 显示全部楼层
嗯,我添加了对任何看起来像光栅的东西的引用,但我仍然不知道如何获得saveas。不过,我找到了2位tif文件的设置
回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2006-12-14 18:11:15 | 显示全部楼层
我没有ARD2007,但ARD2006有一个ActiveX帮助文件。它没有真正的帮助,但有一些关于SaveAs和导出的示例。这是SaveAs:
  1. Sub Example_SaveAs()
  2. ' This example searches through all images in the Current Space and will prompt the
  3. ' user to save all images of the RLC type. This routine then uses a Save As call
  4. ' to save the image using the appropriate image file type. To test this routine,
  5. ' insert at least one RLC image.
  6. ' This calls a procedure to load Cad Overlay. All procedures that use Cad Overlay
  7. ' objects must ensure that Cad Overlay is currently loaded.
  8. EXLoadCadOverlay.Example_EXLoadCadOverlay
  9. ' Declare the necessary variables.
  10. Dim imID As Long ' The Object ID of the images.
  11. Dim imCurName As String ' The currently saved path and name of the image.
  12. Dim imNewName As String ' The new path and name for the image.
  13. Dim I, J As Integer ' For counting.
  14. ' Declare objects to utilize their respective classes.
  15. Dim coList As AecImageObjectList
  16. Dim coWrite As AecImageWrite
  17. Dim coFileName As AecCoImageInfo
  18. ' Set the objects to their respective classes.
  19. Set coList = ThisDrawing.Application.GetInterfaceObject("CADOverlay.AecImageObjectList")
  20. Set coWrite = ThisDrawing.Application.GetInterfaceObject("CADOverlay.AecImageWrite")
  21. Set coFileName = ThisDrawing.Application.GetInterfaceObject("CADOverlay.AecCoImageInfo")
  22. ' Search all images in the current space to determine if they are of type RLC. If they
  23. ' are, prompt the user to save that particular image. CurrentSpaceCount is 0 based; set
  24. ' I = 0 to CurrentSpaceCount -1. The Image Object ID is passed to the AecCoImageInfo
  25. ' object to retrieve the File Name and passed to the AecImageWrite object to write out
  26. ' the file with the Save As method.
  27. For I = 0 To coList.CurrentSpaceCount - 1
  28. imID = coList.CurrentSpaceObjectID(I)
  29. coWrite.ImageObjectID = imID
  30. coFileName.ImageObjectID = imID
  31. imCurName = coFileName.SavedImageFilePath
  32. If Right(coFileName.SavedImageFilePath, 3) = "rlc" Then
  33. J = J + 1
  34. If MsgBox("Save This Image?", vbYesNo, imCurName) = vbYes Then
  35. coWrite.Format = coRLC
  36. imNewName = "c:\Temp" & J & ".rlc"
  37. coWrite.SaveAs (imNewName)
  38. End If
  39. End If
  40. Next
  41. ' Formats supported for Save, Save As, and Export are BMP, RLE, DIB, CAL, GP4, RST, MIL,
  42. ' CG4, FLC, FLI, JPG, PCX, PNG, RLC (with IST header), TGA, TIF.
  43. End Sub

并且帮助确实记录了只需要一个引用:
回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2006-12-15 11:12:47 | 显示全部楼层
好吧,我越来越近了,现在我只需要弄清楚如何反转图像
回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2006-12-15 12:38:00 | 显示全部楼层
好吧,这是超级丑陋的,因为我不得不使用sendCommand 3次(是的,我知道),所以如果有人能看到改进它的方法,我愿意接受建议。
  1. Option Explicit
  2. Public Sub ImgConvert()
  3.     Dim currentline As String, objimg As AcadRasterImage
  4.     Dim inspt(2) As Double
  5.     inspt(0) = 0: inspt(1) = 0: inspt(2) = 0
  6.     Open "c:\jpgconvert.dat" For Input As 1
  7.     While Not EOF(1)
  8.         Line Input #1, currentline
  9.         Set objimg = ThisDrawing.ModelSpace.AddRaster(currentline, inspt, 1, 0)
  10.         ThisDrawing.Regen acAllViewports
  11.         ZoomExtents
  12.         ConvertJPG
  13.         imgdet
  14.     Wend
  15.     Close 1
  16. End Sub
  17. Private Sub imgdet()
  18.     ThisDrawing.SendCommand "-image" & vbCr & "D" & vbCr & "*" & vbCr
  19. End Sub
  20. Private Sub ConvertJPG()
  21.     Dim imgPath As String
  22.     Dim objimg As AcadRasterImage
  23.     Dim imID As Long    ' The Object ID of the images.
  24.     Dim imCurName As String    ' The currently saved path and name of the image.
  25.     Dim imNewName As String    ' The new path and name for the image.
  26.     Dim I, J As Integer    ' For counting.
  27.     ' Declare objects to utilize their respective classes.
  28.     Dim coList As AecImageObjectList
  29.     Dim coFileName As AecCoImageInfo
  30.     Dim coWrite As AecImageWrite
  31.     ' Set the objects to their respective classes.
  32.     Set coList = ThisDrawing.Application.GetInterfaceObject("CADOverlay.AecImageObjectList")
  33.     Set coFileName = ThisDrawing.Application.GetInterfaceObject("CADOverlay.AecCoImageInfo")
  34.     Set coWrite = ThisDrawing.Application.GetInterfaceObject("CADOverlay.AecImageWrite")
  35.     For I = 0 To coList.CurrentSpaceCount - 1
  36.         imID = coList.CurrentSpaceObjectID(I)
  37.         coFileName.ImageObjectID = imID
  38.         coWrite.ImageObjectID = imID
  39.         imCurName = coFileName.SavedImageFilePath
  40.         'imgPath=imCurName
  41.         If Right(imCurName, 3) = "jpg" Then
  42.             J = J + 1
  43.             'If MsgBox("Export This Image?", vbYesNo, imCurName) = vbYes Then
  44.             ' Format each image as a TIFF, add a World File (*.tfw), use an uncompressed
  45.             ' encoding method, Stripped data organization type and Maintain the drawing
  46.             ' link.
  47.             Call imgin
  48.             Call smashitdown
  49.             coWrite.Format = "Tagged Image File Format"
  50.             coWrite.EncodingMethod = "CCITT (Fax) Group 4"
  51.             imNewName = Left(imCurName, Len(imCurName) - 4) & ".tif"
  52.             coWrite.Export (imNewName)
  53.             'End If
  54.         End If
  55.     Next
  56. End Sub
  57. Private Sub imgin()
  58.     ThisDrawing.SendCommand "iinvert" & vbCr
  59. End Sub
  60. Private Sub smashitdown()
  61.     ThisDrawing.SendCommand "_IDEPTH" & vbCr & "B" & vbCr
  62. End Sub

回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2006-12-15 12:51:56 | 显示全部楼层
顺便说一句,光栅必须在运行之前初始化,否则它将严重崩溃
回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2006-12-20 16:50:41 | 显示全部楼层

什么,没有接受者?
回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2006-12-20 17:36:58 | 显示全部楼层
抱歉,我研究了一下,在对象模型中找不到任何允许您消除SendCommands的东西。我以为我发了,但显然我没发那么远。
我知道您可以通过篡改图像字典来删除Imagedefs,因为我编写了一个Lisp来分离无效/未引用的图像。但是反转和深度超出了我对图像的了解。
回复

使用道具 举报

71

主题

928

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1230
发表于 2006-12-21 10:14:54 | 显示全部楼层
谢谢Jeff。我也找不到任何可以摆脱SendCommand ds的东西。我实际上很沮丧,b/c这是我使用过的第一个使用sendCommand的应用程序。
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-7-7 04:55 , Processed in 1.599788 second(s), 71 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表