2012-05-01 3 views
1

일부 응용 프로그램에서 작동 중입니다. 그러나, 나는 스냅 샷을 찍고 또한 비디오를 녹화하기 위해 전화기의 기본 카메라를 호출하는 두 개의 모듈을 마쳤습니다. 나는 휴대 전화 응용 프로그램을 사용하여 이미지와 비디오를 촬영 한 웹 사이트로 보내려합니다. 그러나 텍스트 정보의 경우 이미지 및 비디오 용으로 정보를 문자열로 저장할 수 있습니다. 제출시 Uris로 남겨 두어야할지 확실하지 않습니다. 아래는 내 사진과 비디오 프로그램입니다. 고맙습니다 이미지 코드 :다양한 유형의 비디오 및 이미지

package com.project; 

import java.io.File; 

import android.app.Activity; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.os.Environment; 
import android.provider.MediaStore; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.Toast; 

public class MyPicture extends Activity { 
    /** Called when the activity is first created. */ 
    /*constant and variable created so as to work with the taken pictures*/ 
    private static int TAKE_PICTURE = 1; 
    private Uri outputFileUri; 
    Uri imageUri; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.pic); 
     Button pictureButton=(Button) findViewById(R.id.pictureButton); 
     pictureButton.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       // TODO Auto-generated method stub 
       Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
       File file = new File(Environment.getExternalStorageDirectory(),"test.jpg"); 
       outputFileUri = Uri.fromFile(file); 
       intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); 
       startActivityForResult(intent, TAKE_PICTURE); 

      } 
     }); 
    } 
    @Override 
    protected void onActivityResult(int requestCode,int resultCode, Intent data){ 
     if (requestCode == TAKE_PICTURE){ 
      imageUri = data.getData(); 
      //do something about the image in the in outputFileUri 
      Toast.makeText(MyPicture.this, 
        "Picture successfully taken", 
        Toast.LENGTH_SHORT).show(); 
        Intent i = new Intent(MyPicture.this,/*program execution proceeds back to MyPicture, our start page after success of image takin*/ 
          Myindex.class); 
        startActivity(i); 

     }else{ 
      Toast.makeText(MyPicture.this, 
        "Picture Unsuccessfully taken", 
        Toast.LENGTH_SHORT).show(); 
        Intent i = new Intent(MyPicture.this,/*program execution proceeds back to MyPicture, so we can redo the recording*/ 
          MyPicture.class); 
        startActivity(i); 
     } 

    } 
} 

비디오 코드 : 이미지의 경우

package com.project; 

import android.app.Activity; 
import android.content.Intent; 
import android.net.Uri; 
import android.os.Bundle; 
import android.provider.MediaStore; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.Toast; 

public class MyVideo extends Activity { 
    /*program for the vid button*/ 
    private static int RECORD_VIDEO = 1; 
    private static int HIGH_VIDEO_QUALITY = 1; 
    //private static int MMS_VIDEO_QUALITY = 0; 
    Uri recordedVideo; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.vid); 
     Button videoButton=(Button) findViewById(R.id.videoButton); 
     videoButton.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View arg0) { 
       // TODO Auto-generated method stub 
       Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); 
       //intent.putExtra(MediaStore.EXTRA_OUTPUT, output); 
       intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, HIGH_VIDEO_QUALITY); 
       startActivityForResult(intent, RECORD_VIDEO); 
      } 
     }); 
    } 
    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data){ 
     if (requestCode == RECORD_VIDEO){ 
      recordedVideo = data.getData(); 
      //to do something with the recorded video 
      //we shall insert this information in the database 
      Toast.makeText(MyVideo.this, 
        "Video successfully recorded", 
        Toast.LENGTH_SHORT).show(); 
        Intent i = new Intent(MyVideo.this,/*program execution proceeds back to Myindex, our start page*/ 
          Myindex.class); 
        startActivity(i); 
     } 
     else{ 
      /*Happens after unsuccessfull recording of video*/ 
      Toast.makeText(MyVideo.this, 
        "Video Unsuccessfully recorded", 
        Toast.LENGTH_SHORT).show(); 
        Intent i = new Intent(MyVideo.this,/*program execution proceeds back to MyVideo, so we can redo the recording*/ 
          MyVideo.class); 
        startActivity(i); 
     } 

    } 
} 

답변

0

은 내가 일반적으로 할 것은 Bitmap로 데이터를 디코딩하는 것입니다 그리고 나는 멀티 콘텐츠 형식을 사용하여 HTTP POST를 통해 보내 .

BitmapFactory.decodeFile을 사용하여 이미지 파일을 Bitmap으로 디코딩 할 수 있습니다. 여기

내가 여러 부분이 Apache 라이브러리 사용으로 Bitmap를 보내는 방법의 예입니다 : 비디오 파일의 경우

public String doHttpMultipart(String url, 
            List<NameValuePair> pairs, 
            Bitmap bitmap, 
            String fileName) throws IOException, 
               ClientProtocolException, 
               UnsupportedEncodingException { 
      ByteArrayOutputStream bos = new ByteArrayOutputStream();   
      bitmap.compress(CompressFormat.PNG, 100, bos); 
      byte[] imageData = bos.toByteArray(); 
      ByteArrayBody byteArrayBody = new ByteArrayBody(imageData, fileName); 
      MultipartEntity reqEntity = 
         new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 

      reqEntity.addPart("image", byteArrayBody); 

      for(NameValuePair p : pairs) { 
       reqEntity.addPart(p.getName(), new StringBody(p.getValue())); 
      } 

      HttpPost request = new HttpPost(url); 
      request.setEntity(reqEntity); 

      HttpClient client = new DefaultHttpClient(); 
      HttpResponse httpResponse = client.execute(request); 

      String response = ""; 
      BufferedReader in = null; 

      try { 
       response = super.readHttpStream(response, in, httpResponse);  
      } catch(IllegalStateException e) { 
       throw new IllegalStateException(); 
      } catch(IOException e) { 
       throw new IOException(); 
      } finally { 
       if (in != null) { 
        try { 
         in.close(); 
        } catch (IOException e) { 
         e.printStackTrace(); 
        } 
       } 
      } 

      return response; 
     } 

을, 당신이 바이트의 배열로 디코딩하는 방법을 볼 수 동일해야합니다 멀티 파트로 보내십시오.

관련 문제