Android 无法将位图导出到csv

Android 无法将位图导出到csv,android,Android,我想将一个图像导出到csv,但每当我尝试这样做时,我的应用程序就会崩溃。在我的应用程序中,我有一个问题“您认识哪些品牌?”,希望通过选中复选框以及相应的ImageView让用户回答。目标是通过单击按钮将问题(字符串)和答案(图像)保存到csv或doc,但应用程序崩溃,生成的csv中只打印字符串 public class Page3 extends Activity implements OnClickListener { Intent myIntent; TextView question4;

我想将一个图像导出到csv,但每当我尝试这样做时,我的应用程序就会崩溃。在我的应用程序中,我有一个问题“您认识哪些品牌?”,希望通过选中复选框以及相应的ImageView让用户回答。目标是通过单击按钮将问题(字符串)和答案(图像)保存到csv或doc,但应用程序崩溃,生成的csv中只打印字符串

public class Page3 extends Activity implements OnClickListener {
Intent myIntent;
TextView question4;
CheckBox one, two, three;
ImageView one1, two2, three3;
Bitmap bmp1, bmp2, bmp3;
String ques4;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.page3);
    initialize();
}
    private void initialize() {
    Button prev = (Button) findViewById(R.id.page3previous);
    Button next = (Button) findViewById(R.id.page3next);
    next.setOnClickListener(this);
    prev.setOnClickListener(this);
    question4 = (TextView) findViewById(R.id.question4tv);
    one1 = (ImageView) findViewById(R.id.imageView1);
    two2 = (ImageView) findViewById(R.id.imageView2);
    three3 = (ImageView) findViewById(R.id.imageView3);
    one = (CheckBox) findViewById(R.id.checkBox1);
    two = (CheckBox) findViewById(R.id.checkBox2);
    three = (CheckBox) findViewById(R.id.checkBox3);
}
    @Override
public void onClick(View arg0) {
    switch (arg0.getId()) {
    case R.id.page3previous:
        myIntent = new Intent(Page3.this, Page2.class);
        startActivity(myIntent);
        break;
    case R.id.page3next:
        ques4 = question4.getText().toString();
        if (one.isChecked()) {
            one1.buildDrawingCache();
            bmp1 = one1.getDrawingCache();
            setBitMapOneTwoThree(bmp1, bmp3, bmp2, ques4);
        } else if (two.isChecked()) {
            two2.buildDrawingCache();
            bmp2 = two.getDrawingCache();
            setBitMapOneTwoThree(bmp1, bmp3, bmp2, ques4);
        } else if (three.isChecked()) {
            three3.buildDrawingCache();
            bmp3 = three3.getDrawingCache();
            setBitMapOneTwoThree(bmp1, bmp3, bmp2, ques4);
        } else if (two.isChecked() && one.isChecked()) {
            one1.buildDrawingCache();
            bmp1 = one1.getDrawingCache();
            two2.buildDrawingCache();
            bmp2 = two.getDrawingCache();
            setBitMapOneTwoThree(bmp1, bmp3, bmp2, ques4);
        } else if (two.isChecked() && three.isChecked()) {
            two2.buildDrawingCache();
            bmp2 = two.getDrawingCache();
            three3.buildDrawingCache();
            bmp3 = three3.getDrawingCache();
            setBitMapOneTwoThree(bmp1, bmp3, bmp2, ques4);
        } else if (one.isChecked() && three.isChecked()) {
            three3.buildDrawingCache();
            bmp3 = three3.getDrawingCache();
            one1.buildDrawingCache();
            bmp1 = one1.getDrawingCache();
            setBitMapOneTwoThree(bmp1, bmp3, bmp2, ques4);
        } else if (one.isChecked() && three.isChecked() && two.isChecked()) {
            three3.buildDrawingCache();
            bmp3 = three3.getDrawingCache();
            two2.buildDrawingCache();
            bmp2 = two.getDrawingCache();
            one1.buildDrawingCache();
            bmp1 = one1.getDrawingCache();
            setBitMapOneTwoThree(bmp1, bmp3, bmp2, ques4);
        }
        myIntent = new Intent(Page3.this, Page4.class);
        startActivity(myIntent);
        break;
    }
}
    private void setBitMapOneTwoThree(Bitmap bmp12, Bitmap bmp32, Bitmap bmp22,
        String ques42) {
    bmp12 = this.bmp1;
    bmp32 = this.bmp3;
    bmp22 = this.bmp2;
    ques42 = this.ques4;
    generateCsvFile("Image.csv", bmp12, bmp32, bmp22, ques42);
}

private void generateCsvFile(String string, Bitmap bmp12, Bitmap bmp32,
        Bitmap bmp22, String ques42) {
    try {
        File root = Environment.getExternalStorageDirectory();
        File gpxfile = new File(root, string);
        FileWriter writer = new FileWriter(gpxfile);
        FileOutputStream fOut = new FileOutputStream(gpxfile);
        writer.append(ques42);
        writer.flush();
        writer.close();
        bmp12.compress(Bitmap.CompressFormat.PNG, 85, fOut);
        bmp32.compress(Bitmap.CompressFormat.PNG, 85, fOut);
        bmp22.compress(Bitmap.CompressFormat.PNG, 85, fOut);
        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
}

由于csv是一种文本格式,因此必须先将每个位图编码为其自己的base64字符串,然后才能将其插入csv文件

下面是一个关于我所说内容的快速示例


下面是将图像转换为base64字符串的代码示例。一旦您需要从csv文件中反序列化图像,下面是base64字符串的代码,将其恢复为原始二进制格式

你能从LogCat添加坠机细节吗?