Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 1.77 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. save bitmap as a jpeg file
  2. public static void writePhotoJpg(Bitmap data, String pathName) {
  3.     File file = new File(pathName);
  4.     try {
  5.         file.createNewFile();
  6.         // BufferedOutputStream os = new BufferedOutputStream(
  7.         // new FileOutputStream(file));
  8.  
  9.         FileOutputStream os = new FileOutputStream(file);
  10.         data.compress(Bitmap.CompressFormat.JPEG, 100, os);
  11.         os.flush();
  12.         os.close();
  13.  
  14.  
  15.     } catch (Exception e) {
  16.         e.printStackTrace();
  17.     }
  18. }
  19.        
  20. private Bitmap  printScreen() {
  21.     View view = this.getWindow().getDecorView();
  22.     // if (view.isDrawingCacheEnabled()) {
  23.     view.setDrawingCacheEnabled(true);
  24.     Calendar c = Calendar.getInstance();
  25.     String date = c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1) + "-" + c.get(Calendar.DAY_OF_MONTH) + "  " + c.get(Calendar.HOUR_OF_DAY) + "-" + c.get(Calendar.MINUTE) + "-" + c.get(Calendar.SECOND);
  26.     // }
  27.     view.buildDrawingCache();
  28.  
  29.     Bitmap bmp = view.getDrawingCache();
  30.  
  31.     return  bmp ;
  32. }
  33.        
  34. View v1 = mainLayout.getChildAt(1);     //OR  View v1 = mainLayout.getRootView();  
  35.         v1.setDrawingCacheEnabled(true);
  36.         Bitmap bitmap = Bitmap.createBitmap(v1.getDrawingCache());
  37.         v1.setDrawingCacheEnabled(false);
  38.         return bitmap;
  39.        
  40. public static final int BUFFER_SIZE = 1024 * 8;
  41.  static void writeExternalToCache(Bitmap bitmap, File file) {
  42.     try {
  43.         file.createNewFile();
  44.         FileOutputStream fos = new FileOutputStream(file);
  45.         final BufferedOutputStream bos = new BufferedOutputStream(fos, BUFFER_SIZE);
  46.         bitmap.compress(CompressFormat.JPEG, 100, bos);
  47.         bos.flush();
  48.         bos.close();
  49.         fos.close();
  50.     } catch (FileNotFoundException e) {
  51.         e.printStackTrace();
  52.     } catch (IOException e) {
  53.  
  54.     }
  55.  
  56. }