Java 加工3.0克台摄像机。无法保存图像
您好,我正在使用处理3.0和凯泰库,我正在尝试保存图像,但由于某些原因它无法工作。每个按钮都有自己的侦听器,以便识别是否按下了该按钮。相机正常打开,但按下“保存”按钮时,什么也没有发生。处理控制台中将显示一条错误消息。控制台中显示的消息为: 无法创建保存照片的目录:/storage/emulated/0/Pictures/testing6 testing6是我正在处理的.pde文件。另外,我正在android模拟器上测试应用程序,而不是在android设备上。我希望能够保存图像并创建包含图像的文件夹。例如,一个文件夹将有动物照片,另一个文件夹将有风景,等等。创建任意数量的文件夹和照片。我看到了关于Ketai library和GitHub的文档,但找不到解决方案Java 加工3.0克台摄像机。无法保存图像,java,android,image-processing,android-camera,processing,Java,Android,Image Processing,Android Camera,Processing,您好,我正在使用处理3.0和凯泰库,我正在尝试保存图像,但由于某些原因它无法工作。每个按钮都有自己的侦听器,以便识别是否按下了该按钮。相机正常打开,但按下“保存”按钮时,什么也没有发生。处理控制台中将显示一条错误消息。控制台中显示的消息为: 无法创建保存照片的目录:/storage/emulated/0/Pictures/testing6 testing6是我正在处理的.pde文件。另外,我正在android模拟器上测试应用程序,而不是在android设备上。我希望能够保存图像并创建包含图像的文
import ketai.camera.*;
import java.lang.String.*;
KetaiCamera camera;
void setup()
{
camera = new KetaiCamera(this,width,height/2,15);
// 0: back camera; 1: front camera
camera.setCameraID(0);
}
void draw()
{
image(camera, width/2, height/2, width, height);
drawUI();
}
void drawUI()
{
fill(255);
stroke(0);
orientation(LANDSCAPE);
//here there is a for loop to create the buttons when the camera open
//there are many buttons in other pages that is why we start from 28.
for(int i = 28; i <= 31; i++)
{
buttons[i].draw(color(0,128),textColor);
}
}
void onCameraPreviewEvent()
{
camera.read();
}
void onSavePhotoEvent(String filename)
{
camera.addToMediaLibrary(filename);
}
//mousePressed is a build-in function and I check which button was pressed.
//each button has on click listener.
void mousePressed()
{
if(buttons[28].isPressed()) //button Start, PAGE CAMERA
{
if (camera.isStarted())
{
camera.stop();
}
else
{
if (!camera.start())
{
println("Failed to start camera.");
}
}
}//end of if statement for the START button
else if(buttons[29].isPressed()) //button Save, PAGE CAMERA
{
if(camera.isStarted())
{
camera.savePhoto("test.png");
}
}//end of else if for the SAVE button
else if(buttons[30].isPressed()) //button Flash, PAGE CAMERA
{
if (camera.isFlashEnabled())
{
camera.disableFlash();
}
else
{
camera.enableFlash();
}
}//end of else if statement for the Flash button
else if(buttons[31].isPressed()) //button Exit, PAGE CAMERA
{
camera.stop();
}//end of else if statement for the Exit button
}//end of mousePressed function
导入ketai.camera.*;
导入java.lang.String.*;
凯泰美拉照相机;
无效设置()
{
摄像头=新的KetaiCamera(此,宽度,高度/2,15);
//0:后摄像头;1:前摄像头
摄像头.setCameraID(0);
}
作废提款()
{
图像(相机,宽度/2,高度/2,宽度,高度);
drawUI();
}
void drawUI()
{
填充(255);
冲程(0);
方向(景观);
//这里有一个for循环,用于在相机打开时创建按钮
//其他页面中有许多按钮,这就是为什么我们从28开始。
对于(int i=28;i较新版本的Android,在运行时而不是在安装期间请求用户访问敏感资源的权限。因此,在调用KetaiCamera::savePhoto()
之前,您需要提示用户授予您的应用程序写入文件系统的权限
从:
void setup() {
requestPermission("android.permission.WRITE_EXTERNAL_STORAGE", "checkPermission");
}
void checkPermission(boolean wasPermissionGranted){
if (wasPermissionGranted)
println("Hooray! I can now write to the local file system!");
else
println("Oh no! I was not granted write permission =(");
}