有用代碼片斷


/* protected void doTakePhoto() { 
        try { 
            // Launch camera to take photo for selected contact 
            final Intent intent = getTakePickIntent(mCurrentPhotoFile); 
            startActivityForResult(intent, CAMERA_WITH_DATA); 
        } catch (ActivityNotFoundException e) { 
          
        } 
    } 
 
 public static Intent getTakePickIntent(File f) { 
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE, null); 
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f)); 
        return intent; 
    }  */
 
     // 請求Gallery程序 
   protected void doPickPhotoFromGallery() { 
         try {             
              final Intent intent = getPhotoPickIntent(); 
              startActivityForResult(intent, PHOTO_PICKED_WITH_DATA); 
         } catch (ActivityNotFoundException e) { 
             Toast.makeText(this,"2f3upi",Toast.LENGTH_LONG).show(); 
         } 
   } 
    
 // 封裝請求Gallery的intent 
    public static Intent getPhotoPickIntent() { 
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null); 
        intent.setType("p_w_picpath/*"); 
        intent.putExtra("crop", "true"); 
        intent.putExtra("aspectX", 1); 
        intent.putExtra("aspectY", 1); 
        intent.putExtra("outputX", 80); 
        intent.putExtra("outputY", 80); 
        intent.putExtra("return-data", true); 
        return intent; 
    } 
   
  protected void doCropPhoto(File f) { 
        try {          
            final Intent intent = getCropImageIntent(Uri.fromFile(f)); 
            startActivityForResult(intent, PHOTO_PICKED_WITH_DATA); 
        } catch (Exception e) { 
            Toast.makeText(this, "111111111111111",Toast.LENGTH_LONG).show(); 
        } 
    } 
  public static Intent getCropImageIntent(Uri photoUri) { 
         Intent intent = new Intent("com.android.camera.action.CROP"); 
         intent.setDataAndType(photoUri, "p_w_picpath/*"); 
         intent.putExtra("crop", "true"); 
         intent.putExtra("aspectX", 1); 
         intent.putExtra("aspectY", 1); 
         intent.putExtra("outputX", 80); 
         intent.putExtra("outputY", 80); 
         intent.putExtra("return-data", true); 
         return intent; 
     } 

 
 /**
  *
  *  Bitmap picture = Bitmap.createBitmap( 480, 480, Config.ARGB_8888 );    //建立一張480*480大小的圖片
   Canvas canvasTemp = new Canvas( picture );   //建立畫布
   canvasTemp.drawColor(Color.TRANSPARENT);  //設置畫布透明
   Paint p = new Paint();  
               
   smallpic=Bitmap.createBitmap(bigpic, 0, (count-1)*width, width, width); //從大圖片中取得第count張圖片,從上往下數
   canvasTemp.drawBitmap(smallpic, 0, 0, p); //將取得小圖片畫在畫布上,位置(0,0)
  *   * */
相關文章
相關標籤/搜索