如何通过用C++编写的代码将位图图像保存在Android设备中

How to save Bitmap Image in Android device through code written in C++

本文关键字:存在 保存 图像 Android 位图 C++ 何通过 代码      更新时间:2023-10-16

我正在尝试在Android中保存位图图像,但通过C++功能。我使用流吗?如果是,我应该为创建的ofstream对象提供什么路径?

std::ofstream bmpF;
bmpF.open(<Android Path?>, std::ofstream::binary | std::ofstream::out);

文件名可以是安卓项目中的任何路径。你可以通过 jni 层传递它,并在 java 中从 : context.getFilesDir(( +"/"+

至于 ofstream 的使用:您可以选择以与普通 c/c++ 项目相同的方式写入文件。

文本文件示例

void writeToFile( const char* fileName) {
FILE* fid = fopen(fileName, "w");
if (fid==NULL) {
printf("WriteVectorArt: couldn't open the file");
} else {
fprintf(fid, "SomeText to write");
fclose(fid);
}}

bmpF.open("//storage//emulated//0//pictures//name.bmp",

std::ofstream::binary | std::ofstream::out(;
相关文章: