2011-08-17 5 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); 샘플을 어떻게 편집했는지 편집했습니다. –

관련 문제