将自定义视图保存为SD卡中的图像

时间:2016-09-10 10:21:56

标签: android file canvas view filestream

我想通过将select caller_name as " ", string_agg(coalesce(count::text, '-'), ', ') matrix from ( select t1.name caller_name, t2.name called_name, count from target_groups t1 cross join target_groups t2 left join ( select c1, c2, count(*)::int from ( select g1.target_groups c1, g2.target_groups c2 from call_details c join target_groups_map g1 on c.caller = g1.targets join target_groups_map g2 on c.called = g2.targets ) c group by 1, 2 order by 1, 2 ) c on t1.id = c1 and t2.id = c2 ) sub group by 1 order by 1; | matrix ---------+------------ Group 1 | -, 1, -, 2 Group 2 | 1, -, -, 1 Group 3 | 1, -, 1, 1 Group 4 | -, -, -, - (4 rows) 类扩展为sd卡中的图像来保存我创建的画布。在此视图中,我可以在触摸屏上创建任何行。

自定义视图类:

View

我想将其保存为SD卡中的图像

主要类如下:

public class TouchEventView extends View {
    Paint paint=new Paint();
    Path path=new Path();
    Bitmap myBitmap;
public TouchEventView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
        paint.setAntiAlias(true);
        paint.setColor(Color.BLACK);
        paint.setStrokeJoin(Paint.Join.ROUND);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(5);
    }
@Override
protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);
    canvas.drawPath(path, paint);
    myBitmap=Bitmap.createBitmap((int)canvas.getWidth(), (int)canvas.getHeight(), Config.RGB_565);// bitmap created
    canvas=new Canvas(myBitmap);

}

@Override
public boolean onTouchEvent(MotionEvent event) {
    // TODO Auto-generated method stub
    float xPos=event.getX();
    float yPos=event.getY();
    switch(event.getAction()){
    case MotionEvent.ACTION_DOWN:
        path.moveTo(xPos, yPos);
        return true;
    case MotionEvent.ACTION_MOVE:
        path.lineTo(xPos, yPos);
        break;
    case MotionEvent.ACTION_UP:
        break;
        default:
            return false;

    }
    invalidate();

    return true;


}


}

在主要课程中我使用菜单选项保存画布。点击此图片时,图片应保存在SD卡中。

我已经阅读了许多相关的线程,但都非常复杂。

那么有没有简单的方法可以将画布绘制为图像根据我的代码 在SD卡?

我是初学者所以请解释您的代码答案

我要做的另一件事就是 public class WriteOnScreenActivity extends ActionBarActivity { private String state; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new TouchEventView(this,null)); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.write_on_screen, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.savepic) { state=Environment.getExternalStorageState(); if(state.equals(Environment.MEDIA_MOUNTED)){ File folder; folder=new File(Environment.getExternalStorageDirectory()+"/utkpictdrawn/"); if(!folder.exists()){ folder.mkdirs(); } }else{ Toast.makeText(getBaseContext(), "Cannot Save Image.No SD Card !", Toast.LENGTH_LONG).show(); } return true; } return super.onOptionsItemSelected(item); } } 保存所有内容 来自主要活动的菜单不在onOptionsItemSelected课程中!

0 个答案:

没有答案