|
|

楼主 |
发表于 2025-4-17 16:38
|
显示全部楼层
由于极点坐标是圆形扩散,越外围越会出现投射不到的“空白点”,
查资料,一般采取双列插值方法进行填充,没学会,想了个先放大再缩小的笨方法,勉强处理一下
扇形图片完整代码如下(未优化):
- Sub SecImg() '扇形效果图
- Dim Img, Img1 'As ImageFile
- Dim IP 'As ImageProcess
- Dim v, v1 'As Vector
- Dim f, f1, w As Long, h As Long, w1 As Long, w2 As Long, h1 As Long, h2 As Long, z, t, ps As Integer
- Dim i As Long, j As Long, k As Long, k1 As Long, ii As Long, jj As Long, r As Long, a As Double, jd As Double
- Const pi = 3.1415926
- ''1弧度=57.3度, 1度=0.0174533弧度
- On Error Resume Next
- Set Img = CreateObject("WIA.ImageFile")
- Set Img1 = CreateObject("WIA.ImageFile")
- Set IP = CreateObject("WIA.ImageProcess")
-
- f1 = ThisWorkbook.Path & "\186.bmp"
- Img1.LoadFile f1
- w1 = Img1.width
- h1 = Img1.height
- w = w1 * 1.5
- h = h1 * 1.33
- x = 2.5 '缩放系数: 0 < x < 1 为缩小,大于 1 为放大
- IP.Filters.Add IP.FilterInfos("Scale").FilterID
- IP.Filters(1).Properties("MaximumWidth") = w1 * x
- IP.Filters(1).Properties("MaximumHeight") = h1 * x
- Set Img1 = IP.Apply(Img1)
- Set v1 = Img1.ARGBData
- w1 = Img1.width
- h1 = Img1.height
- Set v = CreateObject("WIA.Vector")
- For z = 1 To w * h
- v.Add &HFFFFFFFF
- 'v.Add 16777215
- Next
- r1 = 250
- cj = w / 2
- ci = h / 2
- jd = 0.62 * pi '旋转角度
- For i = 1 To h1
- For j = 1 To w1
- k1 = (i - 1) * w1 + j
- 'A = 2 * pi * j / w1
- a = -0.75 * pi * j / w1 - jd
- jj = w / 2 + (h1 - i + r1) / x * Sin(a)
- ii = h / 2 + (h1 - i + r1) / x * Cos(a) + r1 - 50
- k = (ii - 1) * w + jj
- v(k) = v1(k1)
- 'For t = k - 2 To k
- ' If v(t) = &HFFFFFFFF Then v(t) = v1(k1)
- 'Next
- Next
- Next
- Set Img = v.ImageFile(w, h)
- f = ThisWorkbook.Path & "\Secp.bmp"
- If Dir(f) <> "" Then Kill f
- Img.SaveFile f '"Blue." & Img.FileExtension
- MsgBox "ok!"
- End Sub
复制代码
|
|