【new Camera.PictureCallback()】

public void onPictureTaken(byte[] data, Camera m_Camera) {
/* Downsize the image from the camera */
Bitmap bImage = BitmapFactory.decodeByteArray( data, 0, data.length);
bImage = Bitmap.createScaledBitmap(bImage, 1200, 900, false);
ByteArrayOutputStream oData = new ByteArrayOutputStream();
bImage.compress( CompressFormat.JPEG, 85, oData);
/* Query image */
String sResult = QueryImage( oData.toByteArray() , reqType);
/* Display Results */
m_Builder.setMessage( sResult);
m_Builder.show();
m_Camera.startPreview();
}

public void onPictureTaken(byte[] imageData, android.hardware.Camera camera) {
if (imageData != null) {
Intent mIntent = new Intent();
compressByteImage(mContext, imageData, 75);
setResult(0, mIntent);//这个就是返回去的消息,setResult在收到消息之后才会被触发返回发送,MainActivity里面的onActivityResult就会对intent里面的result_code(RESULT_OK)处理

//** Send image and offload image processing task to server by starting async task **
ServerTask task = new ServerTask();
task.execute( Environment.getExternalStorageDirectory().toString() + INPUT_IMG_FILENAME);
//start the camera view again .
camera.startPreview();}
}

 //store the image as a jpeg image
    public  boolean compressByteImage(Context mContext, byte[] imageData, int quality) {
    	File sdCard = Environment.getExternalStorageDirectory();
  		FileOutputStream fileOutputStream = null;

  		try {  			 			
  			BitmapFactory.Options options=new BitmapFactory.Options();
  			options.inSampleSize = 1;  	//no downsampling		
  			Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length,options);  	

  			fileOutputStream = new FileOutputStream(sdCard.toString() +INPUT_IMG_FILENAME);							
  			BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
  			//compress image to jpeg
  			myImage.compress(CompressFormat.JPEG, quality, bos);
  			bos.flush();
  			bos.close();  			
  			fileOutputStream.close();  			

  		} catch (FileNotFoundException e) {
   			Log.e(TAG, "FileNotFoundException");
  			e.printStackTrace();
  		} catch (IOException e) {
  			Log.e(TAG, "IOException");
  			e.printStackTrace();
  		}
  		return true;
  	}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

生活在西班牙

自己动手丰衣足食

BlueAsteroid

Just another WordPress.com site

Jing's Blog

Just another WordPress.com site

Start from here......

我的心情魔方

天才遠私廚

希望能做一個分享各種資訊的好地方

语义噪声

西瓜大丸子汤的博客

笑对人生,傲立寰宇

Just another WordPress.com site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision

datarazzi

Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness

槑烎

1,2,∞

Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

%d bloggers like this: