|
楼主 |
发表于 2020-12-2 17:19:47
|
显示全部楼层
本帖最后由 chun2495 于 2020-12-2 17:32 编辑
经过8楼大神“thxcai2”的指点,图像边界已经出来了,效果非常好,也感谢其他坛友的帮忙。
效果图如下:
代码也奉献给有需要的人
- var points3 = [CGPoint]()
- var start_x = image_middle//初始点坐标x
- var start_y = start//初始点坐标y
- points3.append(CGPoint(x: start_x, y: start_y))//第一个初始点
- // 7 8 1
- // 6 0 2
- // 5 4 3
- repeat{
- start_y -= 1//1
- start_x += 1//1
- if(bladder[image_wide*start_y + (start_x - 1)] == 0 && bladder[image_wide*start_y + start_x] == 1){
- points3.append(CGPoint(x: start_x, y: start_y))
- }
- else{
- start_y += 1//2
- if(bladder[image_wide*(start_y - 1) + start_x] == 0 && bladder[image_wide*start_y + start_x] == 1){
- points3.append(CGPoint(x: start_x, y: start_y))
- }
- else{
- start_y += 1//3
- if(bladder[image_wide*(start_y - 1) + start_x] == 0 && bladder[image_wide*start_y + start_x] == 1){
- points3.append(CGPoint(x: start_x, y: start_y))
- }
- else{
- start_x -= 1//4
- if(bladder[image_wide*start_y + (start_x + 1)] == 0 && bladder[image_wide*start_y + start_x] == 1){
- points3.append(CGPoint(x: start_x, y: start_y))
- }
- else{
- start_x -= 1//5
- if(bladder[image_wide*start_y + (start_x + 1)] == 0 && bladder[image_wide*start_y + start_x] == 1){
- points3.append(CGPoint(x: start_x, y: start_y))
- }
- else{
- start_x -= 1//5
- if(bladder[image_wide*start_y + (start_x + 1)] == 0 && bladder[image_wide*start_y + start_x] == 1){
- points3.append(CGPoint(x: start_x, y: start_y))
- }
- else{
- start_y -= 1//6
- if(bladder[image_wide*(start_y + 1) + start_x] == 0 && bladder[image_wide*start_y + start_x] == 1){
- points3.append(CGPoint(x: start_x, y: start_y))
- }
- else{
- start_y -= 1//7
- if(bladder[image_wide*(start_y + 1) + start_x] == 0 && bladder[image_wide*start_y + start_x] == 1){
- points3.append(CGPoint(x: start_x, y: start_y))
- }
- else{
- start_x += 1//8
- if(bladder[image_wide*start_y + (start_x - 1)] == 0 && bladder[image_wide*start_y + start_x] == 1){
- points3.append(CGPoint(x: start_x, y: start_y))
- }
- else{
- print("error!")
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }while(start_x != image_middle || start_y != start)
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|