处理安卓 | save() 函数报错:”文件包含路径分隔符”

huangapple 未分类评论46阅读模式
英文:

Processing for Android | save() "File contains a path separator"

问题

PImage drawing;
void setup() {
  size(displayWidth, displayHeight);
}

boolean clicked = false;
String name = "asdf";

void mouseReleased() {
  clicked = true;
}

void draw() {
  background(255);
  if(drawing != null) {
    image(drawing, 0, 0);
  }
  fill(0);
  noStroke();
  ellipse(mouseX, mouseY, 50, 50);
  if(clicked) {
    save("data/frames/frame" + name + ".tif");
    drawing = loadImage("frames/frame" + name + ".tif");
  }
  
  clicked = false;
}

这是我的代码简化版本。这个简单的程序应该在每次点击时向屏幕上添加一个点。我计划在 frames 文件夹中保存多帧图像。


<details>
<summary>英文:</summary>

I&#39;m using Processing 3.5.4.&lt;br&gt;
I’m trying to `save()` an image of the screen to `data/frames` (relative to my sketch file). The code I’m using works in Java mode with no problems (I can see the image saving into the correct folder on my computer), but when running it on my Android device I get `java.lang.IllegalArgumentException: File data/frames/frameasdf.tif contains a path separator`. I’m guessing this is because of a difference in file storage systems.&lt;br&gt;
&lt;br&gt;
Is there any way I can avoid path separators other than saving images directly into the sketch folder?
I’m new to Java (just moved over from Javascript for more professional development), so if possible, please link to any helpful documentation.

PImage drawing;
void setup() {
size(displayWidth, displayHeight);
}

boolean clicked = false;
String name = "asdf";

void mouseReleased() {
clicked = true;
}

void draw() {
background(255);
if(drawing != null) {
image(drawing, 0, 0);
}
fill(0);
noStroke();
ellipse(mouseX, mouseY, 50, 50);
if(clicked) {
save("data/frames/frame" + name + ".tif");
drawing = loadImage("frames/frame" + name + ".tif");
}

clicked = false;
}

This is a shortened version of my code. It&#39;s a simple program that should add a dot to the screen whenever you click.&lt;br&gt;
I do plan on saving more than one frame in the frames folder.

</details>


# 答案1
**得分**: 0

我对你的问题理解得不是很清楚。你是想将文件保存在特定应用程序文件内还是共享存储文件内?不同存储系统的根文件可以通过Context.getExternalFilesDirs()获得,该方法返回一个文件向量。

你可以从这里开始阅读文档:[Android存储][1]


  [1]: https://developer.android.com/training/data-storage

<details>
<summary>英文:</summary>

I didn&#39;t understand your question very well. Are you trying to save the file inside the specific app files or in shared storage files? the root files of the different storage systems can be got with Context.getExternalFilesDirs() that returns a vector with the files.

you can start reading the documentation here: [Android storage][1]


  [1]: https://developer.android.com/training/data-storage



</details>



huangapple
  • 本文由 发表于 2020年4月6日 13:44:41
  • 转载请务必保留本文链接:https://java.coder-hub.com/61053606.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定