在Cocos2d-x中拍摄相机照片?

时间:2015-08-04 01:34:11

标签: c++ cocos2d-x-3.0

我看到Fennex尝试在Cocos2dx中访问Android的相机API。但在列出的项目中,我不确定我将如何访问相机和相册。有没有办法在Cocos2dx中执行此操作,就像使用Cocos2d一样?

谢谢!

1 个答案:

答案 0 :(得分:0)

This Post says没有cocos2d-x类可以做到这一点,但提供了以下代码段:

它的主旨是,在Android上: - 调用Java代码启动Intent

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
instance.startActivityForResult(cameraIntent, 31); //31 is an ID to recognize that intent yourself

获取Intent返回的Bitmap

Bitmap original = (Bitmap) intent.getExtras().get("data");

最终,根据自己的需要进行扩展(特别是在低端设备上,如果你也从图书馆获取图像)

以您想要的文件格式保存(我使用png)

FileOutputStream stream = new FileOutputStream(path);
/* Write bitmap to file using JPEG or PNG and 80% quality hint for JPEG. */
bitmap.compress(CompressFormat.PNG, 80, stream);
bitmap.recycle(); //ensure the image is freed;
stream.close();

如果你想在iOS上使用相同内容,请查看this post

相关问题