之前我們提過 surfaceview 影像是會移動的. 所以無論你怎麼抓. 都只會有自己的畫面, 而不會有任何相機的影像. 經過一天的實驗, 無論是THREAD.SLEEP 也好, 還是 WHILE(TRUE) 也好. 最後都不能讓使用者一鍵存檔上傳 FACEBOOK. 這樣子 FEEL 就不好了.
所以呢, 我們發現了幾個方法..... 其中之一就是相機影像 READY 之後再 CALL SCREENSHOT. 然後再 上傳 FACEBOOK
PictureCallback jpegPictureCallback = new PictureCallback() {
@Override
public void onPictureTaken(byte[] arg0, Camera arg1) {
ImageView myvv = (ImageView) findViewById(R.id.cambackfround);
//camuse=true;
// TODO Auto-generated method stub
Bitmap resizedBitmap;
try {
Bitmap bitmapPicture = BitmapFactory.decodeByteArray(arg0, 0,
arg0.length);
Matrix matrix = new Matrix();
matrix.postScale(1, 1);
matrix.postRotate(90);
resizedBitmap = null;
try {
resizedBitmap = Bitmap.createBitmap(bitmapPicture, 0, 0,
bitmapPicture.getWidth(), bitmapPicture.getHeight(),
matrix, true);
} catch (Exception e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), "oops! 您要有 SD 卡才能存圖片喔!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
// 大小不變, 先旋轉 90 度 因為我們是直立
int width = resizedBitmap.getWidth();
int height = resizedBitmap.getHeight();
// Log.d("wh","w: "+String.valueOf(width)+" h: "+String.valueOf(height));
float scaleWidth = (float) newwidth / width;
float scaleHeight = (float) newheight / height;
// Log.d("wh","w: "+String.valueOf(scaleWidth)+" h: "+String.valueOf(scaleHeight
// ));
matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
// matrix.postRotate(90);
try {
resizedBitmap = Bitmap.createBitmap(resizedBitmap, 0, 0, width,
height, matrix, true);
} catch (Exception e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), "oops! 您要有 SD 卡才能存圖片喔!",
Toast.LENGTH_LONG).show();
e.printStackTrace();
}
myvv.setImageBitmap(resizedBitmap);
myvv.setVisibility(View.VISIBLE);
ScreenShot.shoot(Mycamera.this);
myvv.setVisibility(View.INVISIBLE);
} catch (Exception e) {
// TODO Auto-generated catch block
Toast.makeText(getApplicationContext(), "oops! 似乎記憶體不足喔, FACEBOOK 功能暫時取消了.",
Toast.LENGTH_LONG).show();
facebook_function=false;
e.printStackTrace();
}
if(camuse==true){
pp_facebook(); // 使用者已經按下上傳 FACEBOOK了. 一樣是啟動相機. 可是在最後才呼叫 FACEBOOK 副程式 //myCamera.startPreview();
//previewing = true;
//sersorrunning = true;
}
myvv.setVisibility(View.INVISIBLE); // 當然機關就是這句了
sersorrunning = true;
myCamera.startPreview();
previewing = true;
camuse=false;
}
};
沒有留言:
張貼留言