|
发表于 2024-8-18 11:45
来自手机
|
显示全部楼层
本帖最后由 lss001 于 2024-8-18 13:47 编辑
'图像变换,以下代码初步完成了变换
Sub DrawSineWave()
Dim img As Object, v As Object, argbs Object
Dim x&, y&, f$, w&, h&, x0&, y0&, k&
f = "D:\1.jpg"
Set img = CreateObject("Wia.ImageFile")
Set v = CreateObject("Wia.Vector")
img.LoadFile f '加载图片
Set argbs = img.ARGBData
w = img.width '宽度高度
h = img.height
r = h * 2.54 / 72: s = 3
x0 = w / 2: y0 = h / 2 '中心
p = WorksheetFunction.Pi
t = WorksheetFunction.RoundUp(2 * p / w, 4)
m = h + r * 2 '画布高度
For i = 1 To m '创建画布
For j = 1 To w
v.Add &HFFFFFFFF
Next
Next
ReDim arr(w - 1): k = 0
For i = -p To p Step t '余弦
arr(k) = i: k = k + 1
Next
k = 1 '左上角开始
For i = 0 To h - 1
For j = w - 1 To 0 Step -1
x = r * arr(j) * s
y = r * Sin(arr(j)) - (y0 - r -1)
v((y0 + y + i -1) * w + x0 - x) = argbs(k)
k = k + 1
Next
Next
Set img = v.ImageFile(w, m)
img.SaveFile "D:\m1.jpg" '保存
Set argbs = Nothing '释放对象
Set v = Nothing
Set img = Nothing
End Sub
|
评分
-
1
查看全部评分
-
|