简体   繁体   English

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

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

I'm trying to save a bitmap image in the Android but through C++ functionality. 我正在尝试通过C ++功能在Android中保存位图图像。 Do I use ofstream? 我是否使用ofstream? And if yes, what path should I give for the ofstream object created? 如果是,我应该为创建的ofstream对象提供什么路径?

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

fileName can be any path in android project. fileName可以是android项目中的任何路径。 You can pass it through jni layer and get same in java from : context.getFilesDir() +"/"+ 您可以将其传递给jni层,并从以下目录中的java中获取相同的内容:context.getFilesDir()+“ /” +

As far as use of ofstream: you may choose to write to file in same way as you would in normal c/c++ project. 至于ofstream的使用:您可以选择以与普通c / c ++项目相同的方式写入文件。

Text file example 文字档案范例

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(“ //存储//仿真// 0 //图片//name.bmp”,std :: ofstream :: binary | std :: ofstream :: out);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM