1

我正在開發一個應用程序,我使用一個按鈕來加載相機,並需要在我的應用程序中附加這些圖片。我在加載相機時沒有問題,但我無法附加在應用程序中使用相機拍攝的照片。任何人都可以提供一個好的解決方案(提前) Swetha Kaulwar。如何在我的應用程序中附加使用相機拍攝的照片?

+0

附着其中?? – 2012-03-15 06:45:27

+0

你想附加在哪裏? – 2012-03-15 06:45:35

+0

在我創建的應用程序中。 – 2012-03-15 06:46:16

回答

2

我這樣做,我onActivityResult ...我從拍攝意圖PIC減少它的大小,並將其添加到這是後來添加到自定義的ListView列表...我希望這有助於你的一點改進

if (resultCode == Activity.RESULT_OK) { 

      Bundle extras = intent.getExtras(); 
      Bitmap bitmap = (Bitmap) extras.get("data"); 


      int width = bitmap.getWidth(); 
      Log.i("size width:", String.valueOf(width)); 
      int height = bitmap.getHeight(); 
      Log.i("size height:", String.valueOf(height)); 

      float widthPercent = (float) 0.8; 
      float heightPercent = (float) 0.8; 

      float newWidth = bitmap.getWidth() * widthPercent; 
      float newHeight = bitmap.getHeight() * heightPercent; 

      while (newWidth > 250 || newHeight > 250) { 

      newWidth = newWidth * widthPercent; 
      Log.i("size width:", String.valueOf(newWidth)); 
      newHeight = newHeight * heightPercent; 
      Log.i("size height:", String.valueOf(newHeight)); 
      } 




      // calculate the scale - in this case = 0.4f 
      float scaleWidth = ((float) newWidth)/width; 
      Log.i("new size width:", String.valueOf(scaleWidth)); 
      float scaleHeight = ((float) newHeight)/height; 
      Log.i("new size height:", String.valueOf(scaleHeight)); 

      Matrix matrix = new Matrix(); 

      // resize the bit map 
      matrix.postScale(scaleWidth, scaleHeight); 

      // recreate the new Bitmap 
      Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, 
      width, height, matrix, true); 

      Log.i("new bitmap width:", 
      String.valueOf(resizedBitmap.getWidth())); 
      Log.i("new bitmap height:", 
      String.valueOf(resizedBitmap.getHeight())); 

      App.serviceCallImages.add(resizedBitmap); 

      Adapter.notifyDataSetChanged(); 

      break; 
     } 

繼承人我相機意圖代碼

public void OnCameraOpen(View v) { 

    if (App.serviceCallImages.size() < 2) { 
     Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

     startActivityForResult(intent, CAPTURE_PICTURE_INTENT); 
    } else { 
     Toast.makeText(getApplicationContext(), getString(R.string.MaxPics), 
       Toast.LENGTH_SHORT).show(); 
    } 

} 
相關問題