我正在尝试将我的视图保存为图像。我做了一些工作,没有显示任何错误,但我可以找到保存图像的位置(或在图库中)。图像是完全创建的,还是我有其他问题?从选项菜单中按红色时应保存图像:
case R.id.red:
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
String FILENAME="Boenka";
FileOutputStream fos = null;
try {
fos = openFileOutput(FILENAME, Context.MODE_WORLD_READABLE);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
parent.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap( parent.getWidth(), parent.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
parent.draw(canvas);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
return true;
这是我的主要 - 绘图类
public class Draw extends Activity {
DrawView drawView;
SignatureView signature;
private RelativeLayout parent;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
parent = (RelativeLayout) findViewById(R.id.signImageParent);
signature = new SignatureView(getApplicationContext(), null);
signature.setColor(Color.MAGENTA);
parent.addView(signature);
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_options_menu, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.clear:
signature.clear();
return true;
case R.id.red:
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
String FILENAME="Boenka";
FileOutputStream fos = null;
try {
fos = openFileOutput(FILENAME, Context.MODE_WORLD_READABLE);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
parent.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap( parent.getWidth(), parent.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
parent.draw(canvas);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
return true;
case R.id.blue:
signature.setColor(Color.BLUE);
return true;
case R.id.yellow:
signature.setColor(Color.YELLOW);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
@Override
public void onBackPressed() {
this.finish();
super.onBackPressed();
}
}