2011-08-17 67 views
0

我想創建一個應用程序拍攝照片並重新顯示應用程序。 但我的感覺與我的HTC代碼不起作用,當我在三星上測試它,它的工作原理。我對HTC的應用程序的感覺問題android應用程序

我的代碼:

public class CameraDemo extends Activity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     final Button cameraButton = (Button) findViewById(R.id.button1); 
     cameraButton.setOnClickListener(new View.OnClickListener(){ 
     public void onClick(View v){ 
      Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
      startActivityForResult(intent, 0); 
     } 
     }); 
    } 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if (requestCode== 0 && resultCode == Activity.RESULT_OK){ 
      final ImageView iv = (ImageView) findViewById(R.id.imageView1); 
      iv.setImageBitmap((Bitmap) data.getExtras().get("data")); 
     } 
    } 
} 

你能幫助我理解爲什麼它不會對我的HTC感工作,同時它可以在另一部手機。

謝謝。

+0

什麼「它母鹿不工作「的意思?請更具體地 – Egor

+0

打算運行它,我拍了照片,並關閉應用程序而不顯示照片。 –

+0

是否有任何異常拋出? – Egor

回答

0

我在使用HTC相機時遇到了這個問題。

從我記得HTC /檢測處理回照片略有不同,下面是我做到了,希望能夠處理處理照片的兩個變種一些僞..

public static void StartCameraActivity() 
{ 
     Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE, null); 
     // Create the directory if it's not there 
     File photoDir = new File(Environment.getExternalStorageDirectory() + "/.pics/"); 
     photoDir.mkdirs(); 

     // Construct the file.. 
     String fileName = File.separator + ".pics/photo" + String.valueOf(System.currentTimeMillis()) + ".jpg"; 
     File file = new File(Environment.getExternalStorageDirectory(), fileName); 
     // Create the intent and remember the place we asked for the file to be placed 
     intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); 
     intent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, LinearLayout.VERTICAL); 

     _outputFileUri = Uri.fromFile(file); 
     context.getActivity().startActivityForResult(intent, 1); 
    } 

Bitmap bm = null; 
    BitmapFactory.Options options = new BitmapFactory.Options(); 
     options.inSampleSize = SAMPLE_SIZE; 
     try 
     { 
      bm= (Bitmap) data.getExtras().get("data"); 
      FileOutputStream out = new FileOutputStream(_outputFileUri.getPath()); 
      bm.compress(Bitmap.CompressFormat.JPEG, 100, out); 
     } 
     catch (NullPointerException ex) 
     { 
      bm = OtherImageProcessing(options); 
     } 
     catch (Exception e) 
     { 
      throw new Exception("Problem occured.", e); 
     } 

public static Bitmap OtherImageProcessing(BitmapFactory.Options options) throws Exception 
{ 
    Bitmap bm = null; 

    try 
    { 
     FileInputStream fis = new FileInputStream(_outputFileUri.getPath()); 
     BufferedInputStream bis = new BufferedInputStream(fis); 
     bm = BitmapFactory.decodeStream(bis, null, options); 

     // cleaning up 
     fis.close(); 
     bis.close(); 
    } 
    catch (Exception e) 
    { 
     throw new Exception("Problem", e); 
    } 

    return bm; 
} 

希望幫助...

+0

pathToPhoto對應於什麼? –

+0

pathToPhoto應該對應於:_outputFileUri,它是在第一個代碼塊_outputFileUri = Uri.fromFile(file)中設置的; 我編輯了樣本以瞭解它們應該如何 –

相關問題