2011-02-02 94 views
3

這被轉發到下一個畫面是我的代碼圖像應在android系統

package com.marakana; 

import java.io.File; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.IOException; 

import android.app.Activity; 
import android.content.Intent; 
import android.hardware.Camera; 
import android.hardware.Camera.PictureCallback; 
import android.hardware.Camera.ShutterCallback; 
import android.net.Uri; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.FrameLayout; 
import android.widget.Toast; 

public class CameraActivity extends Activity { 
    private static final String TAG = "CameraDemo"; 
    Preview preview; // <1> 
    Button buttonClick; // <2> 
    myglobal m=new myglobal(); 
    String aa; 
    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    preview = new Preview(this); // <3> 
    ((FrameLayout) findViewById(R.id.preview)).addView(preview); // <4> 

    buttonClick = (Button) findViewById(R.id.buttonClick); 
    buttonClick.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { // <5> 
     preview.camera.takePicture(shutterCallback, rawCallback, jpegCallback); 
     } 
    }); 

    Log.d(TAG, "onCreate'd"); 
    } 

    // Called when shutter is opened 
    ShutterCallback shutterCallback = new ShutterCallback() { // <6> 
    public void onShutter() { 
     Log.d(TAG, "onShutter'd"); 
    } 
    }; 

    // Handles data for raw picture 
    PictureCallback rawCallback = new PictureCallback() { // <7> 
    public void onPictureTaken(byte[] data, Camera camera) { 
     Log.d(TAG, "onPictureTaken - raw"); 
    } 
    }; 

    // Handles data for jpeg picture 
    PictureCallback jpegCallback = new PictureCallback() { // <8> 
    public void onPictureTaken(byte[] data, Camera camera) { 
     FileOutputStream outStream = null; 
     try { 
     // Write to SD Card 


      outStream = new FileOutputStream(String.format("/sdcard/DCIM/%d.jpg", 
      System.currentTimeMillis())); 

      m.setAa(aa); 
     Toast.makeText(getBaseContext(),aa,1000).show(); 
     outStream.write(data); 
     outStream.close(); 
     Log.d(TAG, "onPictureTaken - wrote bytes: " + data.length); 
     Intent i=new Intent(); 
     i.setClassName("com.marakana", "com.marakana.image"); 
     startActivity(i); 
     } catch (FileNotFoundException e) { // <10> 
     e.printStackTrace(); 
     } catch (IOException e) { 
     e.printStackTrace(); 
     } finally { 
     } 
     Log.d(TAG, "onPictureTaken - jpeg"); 
    } 
    }; 

} 
+0

訪問路徑讓你的問題更精確和易於閱讀。現在它真的很痛苦讀這個.. – Javanator 2011-02-02 08:34:52

+0

這是我的代碼...和問題? – 2013-07-13 14:25:30

回答

2

我認爲其更好您發送您的路徑下一個活動。所以你可以從這個活動中讀到它。

String path = String.format("/sdcard/DCIM/%d.jpg",System.currentTimeMillis()); 
outStream = new FileOutputStream(path); 
//other codes 
Intent i=new Intent(); 
i.setClassName("com.marakana", "com.marakana.image"); 
i.putExtra("path", path); 
startActivity(i); 

所以,你可以通過

String path = getIntent().getExtra("path"); 
//so you can create drawable or bitmap using this path 
0
i.putExtra("img", data); 

然後在另一個活動只是使用

getIntent().getExtra("img");