Thứ Ba, 27 tháng 8, 2013


getBitmapFromView
public static Bitmap getBitmapFromView(View view) {
    Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(),Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(returnedBitmap);
    Drawable bgDrawable =view.getBackground();
    if (bgDrawable!=null) 
        bgDrawable.draw(canvas);
    else 
        canvas.drawColor(Color.WHITE);
    view.draw(canvas);
    return returnedBitmap;
}

and save to sdcard

private void createPointsImage(Bitmap bm, String image_name){
  try {
   output=proccessPath+image_name;
   
   File file=new File(proccessPath);
   if(!file.exists())
    file.mkdirs();
   
      File filepath=new File(file, image_name);
      filepath.createNewFile();
      
         OutputStream fOut = null;
         fOut = new FileOutputStream(filepath);
         bm.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
         fOut.flush();
         fOut.close();
     }
     catch (Exception e) {
         e.printStackTrace();
     }
    }

Không có nhận xét nào:

Đăng nhận xét