行业需要,需要对DWG工程图上的部分图形抓取下来,保存为JPG的格式。参考了一下以前系统的模式,觉得非常复杂,不好实现。碰到两个问题,1如何抓图;2如何自动定位。也问了以前系统的实施人,呵呵~没有人告诉。后来自己实现了,原来很简单。看来还是靠自己,需要自己动手阿~~~~会了不难,难了不会。没什么技术含量,贴出来,其他有用的着的朋友可以借鉴。免费给大家。。。。
1、安装Volo View Express
2、用VB6做,其实什么语言都可以,不过可视化的比较快。VBA都可以
3、
4、拖动DWG到窗体,自动定位到简图的位置,(这是以前系统开发方要求的,延续使用)
5、代码如下:
Option Explicit
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Const SRCCOPY = &HCC0020
'抓取窗体上固定区域,左上角座标(X,Y),宽度W,高度H
'并保存到文件中
Private Const X As Long = 10
Private Const Y As Long = 10
Private Const W As Long = 140
Private Const H As Long = 100
Private Sub Command1_Click()
Picture1.Width = W
Picture1.Height = H
'实际保存宽度为W-4,高度为H-4
BitBlt Picture1.hDC, 0, 0, W - 4, H - 4, Me.hDC, X, Y, SRCCOPY
SavePicture Picture1.Image, Label4.Caption
End Sub
Private Sub Form_Load()
Me.ScaleMode = 3
Picture1.ScaleMode = 3
Picture1.AutoRedraw = True
Form1.OLEDropMode = vbOLEDropManual
End Sub
Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Data.GetFormat(vbCFFiles) Then
Dim i As Long
For i = 1 To Data.Files.Count
Debug.Print , Data.Files(i)
Label3.Caption = Data.Files(i)
Next
End If
If Right(Label3.Caption, 4) = ".dwg" Then
Label4.Caption = Replace(Label3.Caption, ".dwg", ".jpg")
AvViewX1.src = Label3.Caption
End If
End Sub
|
文件: |
pict2.rar |
大小: |
199KB |
下载: |
下载 | |
阅读(926) | 评论(0) | 转发(0) |