用Android实现将图片拉伸成stl格式

本文是实现在Android平台上,将png、jpg等格式图片拉伸成stl格式,以便用于3D打印。
具体实现:在Android平台上,通过chaquopy方案,调用cura源码中,将二维模型图片拉伸成stl格式三维模型的python代码实现。
1、cura中拉伸部分代码提取和修改

cura源码中主要函数:(image.py)

Android将png等图片拉伸成stl文件格式用于3D打印
读取图像,并根据输入参数,对图像进行拉伸。
Android将png等图片拉伸成stl文件格式用于3D打印
创建并保存stl文件
Android将png等图片拉伸成stl文件格式用于3D打印
将拉伸后的图像数据,按二进制stl格式写入文件

代码修改
将pyqt5用pillow替换掉:
Android将png等图片拉伸成stl文件格式用于3D打印
Android将png等图片拉伸成stl文件格式用于3D打印
Android将png等图片拉伸成stl文件格式用于3D打印
Android将png等图片拉伸成stl文件格式用于3D打印
将cura15.04和cura4.2两个版本图像拉伸代码相结合,拼凑出我们想要的最终代码,以实现在Android上png转stl功能。
cura15.04使用的是 python2代码,cura4.2使用的是python3代码,两者区别可百度。
python2和python3拉伸代码结合,得到整个过程的主要函数:
Android将png等图片拉伸成stl文件格式用于3D打印
Android将png等图片拉伸成stl文件格式用于3D打印
Android将png等图片拉伸成stl文件格式用于3D打印
Android将png等图片拉伸成stl文件格式用于3D打印
涉及到其他函数中的代码,报错的地方全部注释掉
Android将png等图片拉伸成stl文件格式用于3D打印
Android将png等图片拉伸成stl文件格式用于3D打印
2、将提取的代码到Android移植:用chaquopy方案实现

在工程目录下的build.gradle里添加如下:
Android将png等图片拉伸成stl文件格式用于3D打印
在app目录下的build.gradle添加:
使用插件:
Android将png等图片拉伸成stl文件格式用于3D打印
指定NDK:
Android将png等图片拉伸成stl文件格式用于3D打印
Python路径:
Android将png等图片拉伸成stl文件格式用于3D打印
pip导入第三方库:
Android将png等图片拉伸成stl文件格式用于3D打印
在生成的python文件夹中导入python代码:
Android将png等图片拉伸成stl文件格式用于3D打印
在mainactivity中初始化python环境,并对python代码进行传参调用:
Android将png等图片拉伸成stl文件格式用于3D打印
Android将png等图片拉伸成stl文件格式用于3D打印
输出文件位置声明:
Android将png等图片拉伸成stl文件格式用于3D打印
运行结果:
Android将png等图片拉伸成stl文件格式用于3D打印
成功生成stl文件。如果对代码有任何问题,可以联系本尊,扣扣:1335823306

相关文章:

  • 2022-12-23
  • 2021-04-07
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2021-08-30
  • 2021-06-01
  • 2021-11-26
猜你喜欢
  • 2021-12-21
  • 2021-11-18
  • 2022-12-23
  • 2021-10-30
  • 2021-11-18
  • 2021-11-09
  • 2022-12-23
相关资源
相似解决方案