相关疑难解决方法(0)

如何在内部存储上保存位图

这是我的代码我想在内部存储上保存这个位图.公共布尔saveImageToInternalStorage是来自谷歌的代码,但我不知道如何使用它.当我触摸button2时,按下button1动作.

public class MainActivity extends Activity implements OnClickListener {
Button btn, btn1;
SurfaceView sv;
Bitmap bitmap;
Canvas canvas;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    btn=(Button)findViewById(R.id.button1);
    btn1=(Button)findViewById(R.id.button2);
    sv=(SurfaceView)findViewById(R.id.surfaceView1);

    btn.setOnClickListener(this);
    btn1.setOnClickListener(this);

    bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

}
@Override
public void onClick(View v) {
    canvas=sv.getHolder().lockCanvas();
    if(canvas==null) return;
    canvas.drawBitmap(bitmap, 100, 100, null);
    sv.getHolder().unlockCanvasAndPost(canvas);


}

public boolean saveImageToInternalStorage(Bitmap image) {

    try {
    // Use the compress method on the Bitmap object to write image to
    // the OutputStream
    FileOutputStream fos = openFileOutput("desiredFilename.png", Context.MODE_PRIVATE);

    // Writing the …
Run Code Online (Sandbox Code Playgroud)

android bitmap save

38
推荐指数
2
解决办法
11万
查看次数

标签 统计

android ×1

bitmap ×1

save ×1