关于“类型不匹配”的错误
我用以下程序获取psd文档中某个像素(x,y)的颜色值,运行到最后一句出现“类型不匹配”的错误,请高手解决一下。
public appRef As Object, docRef As Object
sub getColor(X As Integer, Y As Integer)
Set appRef = CreateObject("Photoshop.Application")
Set docRef = appRef.Open("c:\a.psd")
docRef.Selection.Select Array(Array(X, Y), Array(X + 1, Y), Array(X + 1, Y + 1), Array(X, Y + 1))
getcolor=docRef.channels(1).Histogram(1)
end sub
[解决办法]
改成这样试试
Private Function getColor(X As Integer, Y As Integer) As Long
Set appRef = CreateObject("Photoshop.Application")
Set docRef = appRef.Open("c:\ss.bmp")
docRef.Selection.Select Array(Array(X, Y), Array(X + 1, Y), Array(X + 1, Y + 1), Array(X, Y + 1))
getColor = docRef.channels(1).Histogram(1)
End Function
我用以下程序获取psd文档中某个像素(x,y)的颜色值,运行到最后一句出现“类型不匹配”的错误
Private Function getColor(X As Integer, Y As Integer) As integer
Set appRef = CreateObject("Photoshop.Application")
Set docRef = appRef.Open("c:\ss.psd")
docRef.Selection.Select Array(Array(X, Y), Array(X + 1, Y), Array(X + 1, Y + 1), Array(X, Y + 1))
getColor = docRef.channels(1).Histogram(1)
End Function
但如果在工程中引用adobe photoshop 8.0 object library库,再对变量appRef和docref作如下定义,程序就正常了,但如果安装了不同版本的photoshop,需要引用不同的库,局限性较大
Private Function getColor(X As Integer, Y As Integer) As integer
Dim appRef As New Photoshop.Application
Dim docref As Photoshop.Document
Set docRef = appRef.Open("c:\ss.psd")
docRef.Selection.Select Array(Array(X, Y), Array(X + 1, Y), Array(X + 1, Y + 1), Array(X, Y + 1))
getColor = docRef.channels(1).Histogram(1)
End Function
[解决办法]
可最后一句是End Sub呀
[解决办法]