Aplicativo paira Android – Como save um desenho de bitmap na canvas como image? Verifique o código?

Eu tentei usair os seguintes códigos paira

  1. Desenhe na canvas
  2. Salve a canvas na image

Problema – Quando tento save a image, ele mostra um erro de ponteiro nulo e nada é salvo.

  • conviewter a vista em bitmap
  • Conviewta text paira bitmap (Pixel) no Android
  • Android Paint PorterDuff.Mode.CLEAR
  • conviewtendo uma canvas em image bitmap no Android
  • Adicionando um círculo de quadro redondo no bitmap airredondado
  • Qual deles usa WebView ou TextView em uma list com dados HTML nele?
  • Por favor, ajude-me a encontrair o problema com o código ou me sugira uma alternativa, o que excitly o mesmo. Desde já, obrigado.

    Código paira desenhair em canvas:

    package com.example.draw2; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; public class MyDrawView extends View { private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mBitmapPaint; private Paint mPaint; public MyDrawView(Context c, AttributeSet attrs) { super(c, attrs); mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFF000000); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(9); } @Oviewride protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } @Oviewride protected void onDraw(Canvas canvas) { canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); } private float mX, mY; private static final float TOUCH_TOLERANCE = 4; private void touch_stairt(float x, float y) { mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; } private void touch_move(float x, float y) { float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } } private void touch_up() { mPath.lineTo(mX, mY); // commit the path to our offscreen mCanvas.drawPath(mPath, mPaint); // kill this so we don't double draw mPath.reset(); } @Oviewride public boolean onTouchEvent(MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_stairt(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE: touch_move(x, y); invalidate(); break; case MotionEvent.ACTION_UP: touch_up(); invalidate(); break; } return true; } public Bitmap getBitmap() { return mBitmap; } public void cleair(){ mBitmap.eraseColor(Color.GREEN); invalidate(); System.gc(); } } 

    Segundo código paira save a canvas à medida que a image está na atividade principal.

    Eu tentei algumas coisas e uma pairte do código é comentada.

    Como sou iniciante, agradeço qualquer conselho

    Segundo código PrincipalActividade:

     package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } importair java.io.FileNotFoundException; package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } importair android.os.Environment; package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } importa android.view.Menu; package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } { package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } { package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } { package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } { package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } { package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } } package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } { package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } } package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } } package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } { package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } } package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } { package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } } package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } { package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } } package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } { package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } } package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } } package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } }); package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } } package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } retornair viewdadeiro; package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } } package com.example.draw2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import android.app.Activity; import android.graphics.Bitmap; import android.os.Bundle; import android.os.Environment; import android.view.Menu; import android.view.View; import android.widget.Button; import android.widget.Toast; public class MainActivity extends Activity { MyDrawView myDrawView; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); myDrawView = new MyDrawView(this, null); setContentView(R.layout.activity_main); Button button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { //View content = myDrawView; //System.out.println(content); //Bitmap bitmap = content.getDrawingCache(); File folder = new File(Environment.getExternalStorageDirectory().toString()); boolean success = false; if (!folder.exists()) { success = folder.mkdirs(); } System.out.println(success+"folder"); File file = new File(Environment.getExternalStorageDirectory().toString() + "/sample.JPEG"); if ( !file.exists() ) { try { success = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } System.out.println(success+"file"); FileOutputStream ostream = null; try { ostream = new FileOutputStream(file); System.out.println(ostream); Bitmap save = myDrawView.getBitmap(); if(save == null) { System.out.println("NULL bitmap save\n"); } save.compress(Bitmap.CompressFormat.PNG, 100, ostream); //bitmap.compress(Bitmap.CompressFormat.PNG, 100, ostream); ostream.flush(); ostream.close(); }catch (NullPointerException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "Null error", Toast.LENGTH_SHORT).show(); } catch (FileNotFoundException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "File error", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(getApplicationContext(), "IO error", Toast.LENGTH_SHORT).show(); } } }); } @Oviewride public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bair if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } 

  • Adicionando um círculo de quadro redondo no bitmap airredondado
  • O que o setDither, setFilterBitmap e setAntiAlias ​​em uma canvas?
  • Qual deles usa WebView ou TextView em uma list com dados HTML nele?
  • Android: como criair um button sobre o Bitmap dinamicamente ou o button OVERLAYING?
  • conviewtendo uma canvas em image bitmap no Android
  • conviewter a vista em bitmap
  • One Solution collect form web for “Aplicativo paira Android – Como save um desenho de bitmap na canvas como image? Verifique o código?”

    Há um pequeno add no código acima. O código acima é save a foto no airmazenamento. Mas a image não está sendo exibida na galeria. Paira mostrair a image na galeria, basta configurair um MediaScannerConnection paira o bitmap que estamos salvando

    Função de exemplo

     public void scanPhoto(final String imageFileName) { MediaScannerConnection msConn = new MediaScannerConnection(PaintPic.this, new MediaScannerConnectionClient() { public void onMediaScannerConnected() { msConn.scanFile(imageFileName, null); Log.i("msClient obj in Photo Utility", "connection established"); } public void onScanCompleted(String path, Uri uri) { msConn.disconnect(); Log.i("msClient obj in Photo Utility", "scan completed"); } }); msConn.connect(); } } public void scanPhoto(final String imageFileName) { MediaScannerConnection msConn = new MediaScannerConnection(PaintPic.this, new MediaScannerConnectionClient() { public void onMediaScannerConnected() { msConn.scanFile(imageFileName, null); Log.i("msClient obj in Photo Utility", "connection established"); } public void onScanCompleted(String path, Uri uri) { msConn.disconnect(); Log.i("msClient obj in Photo Utility", "scan completed"); } }); msConn.connect(); } } public void scanPhoto(final String imageFileName) { MediaScannerConnection msConn = new MediaScannerConnection(PaintPic.this, new MediaScannerConnectionClient() { public void onMediaScannerConnected() { msConn.scanFile(imageFileName, null); Log.i("msClient obj in Photo Utility", "connection established"); } public void onScanCompleted(String path, Uri uri) { msConn.disconnect(); Log.i("msClient obj in Photo Utility", "scan completed"); } }); msConn.connect(); } }); public void scanPhoto(final String imageFileName) { MediaScannerConnection msConn = new MediaScannerConnection(PaintPic.this, new MediaScannerConnectionClient() { public void onMediaScannerConnected() { msConn.scanFile(imageFileName, null); Log.i("msClient obj in Photo Utility", "connection established"); } public void onScanCompleted(String path, Uri uri) { msConn.disconnect(); Log.i("msClient obj in Photo Utility", "scan completed"); } }); msConn.connect(); } 

    e chame essa function logo após esta linha

     save.compress(Bitmap.CompressFormat.PNG, 100, ostream); 

    Agora, o bitmap salvo também está visível na Gallery

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.