第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Android攝像機(jī):數(shù)據(jù)意圖返回空

Android攝像機(jī):數(shù)據(jù)意圖返回空

qq_笑_17 2019-07-11 21:13:23
Android攝像機(jī):數(shù)據(jù)意圖返回空我有一個(gè)Android應(yīng)用程序,它包含多個(gè)活動(dòng)。在其中一種情況下,我使用一個(gè)按鈕來(lái)調(diào)用設(shè)備攝像機(jī):public void onClick(View view) {     Intent photoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);     startActivityForResult(photoIntent, IMAGE_CAPTURE);}在相同的活動(dòng)中,我稱之為OnActivityResult方法獲取圖像結(jié)果:@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {     if (requestCode == IMAGE_CAPTURE) {         if (resultCode == RESULT_OK) {             Bitmap image = (Bitmap) data.getExtras().get("data");             ImageView imageview = (ImageView) findViewById(R.id.pic);             imageview.setImageBitmap(image);         } else if (resultCode == RESULT_CANCELED) {             Toast.makeText(this, "CANCELED ", Toast.LENGTH_LONG).show();         }     }}問題是data為空,而OnActivityResult方法直接轉(zhuǎn)到(resultCode == RESULT_CANCELED)并且應(yīng)用程序返回到以前的avtivity。如何解決此問題,并且在調(diào)用攝像機(jī)之后,應(yīng)用程序返回到當(dāng)前活動(dòng),其中包含ImageView哪個(gè)將包含拍攝的照片?謝謝
查看完整描述

3 回答

?
慕妹3146593

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超9個(gè)贊

我找到了一個(gè)簡(jiǎn)單的答案。起作用了!

o

private void openCameraForResult(int requestCode){
    Intent photo = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    Uri uri  = Uri.parse("file:///sdcard/photo.jpg");
    photo.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri);
    startActivityForResult(photo,requestCode);}if (requestCode == CAMERA_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            File file = new File(Environment.getExternalStorageDirectory().getPath(), "photo.jpg");
            Uri uri = Uri.fromFile(file);
            Bitmap bitmap;
            try {
                bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
                bitmap = crupAndScale(bitmap, 300); // if you mind scaling
                pofileImageView.setImageBitmap(bitmap);
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    }

如果你想要裁剪和縮放這個(gè)圖像

public static  Bitmap crupAndScale (Bitmap source,int scale){
    int factor = source.getHeight() <= source.getWidth() ? source.getHeight(): source.getWidth();
    int longer = source.getHeight() >= source.getWidth() ? source.getHeight(): source.getWidth();
    int x = source.getHeight() >= source.getWidth() ?0:(longer-factor)/2;
    int y = source.getHeight() <= source.getWidth() ?0:(longer-factor)/2;
    source = Bitmap.createBitmap(source, x, y, factor, factor);
    source = Bitmap.createScaledBitmap(source, scale, scale, false);
    return source;}


查看完整回答
反對(duì) 回復(fù) 2019-07-11
  • 3 回答
  • 0 關(guān)注
  • 525 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)