【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】Android中視頻采集的示例分析_第1頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】Android中視頻采集的示例分析_第2頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】Android中視頻采集的示例分析_第3頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】Android中視頻采集的示例分析_第4頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】Android中視頻采集的示例分析_第5頁(yè)
免費(fèi)預(yù)覽已結(jié)束,剩余1頁(yè)可下載查看

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】Android中視頻采集的示例分析

Camera基礎(chǔ)知識(shí)權(quán)限聲明<uses-permission

android:name="android.permission.CAMERA"

/><uses-feature

android:name="android.hardware.camera"

/><uses-permission

android:name="android.permission.RECORD_AUDIO"

/><uses-permission

android:name="android.permission.WRITE_EXTERNAL_STORAGE"

/><uses-permission

android:name="android.permission.ACCESS_FINE_LOCATION"

/>

...

<!--

Needed

only

if

your

app

targets

Android

5.0

(API

level

21)

or

higher.

-->

<uses-feature

android:name="android.hardware.location.gps"

/>調(diào)用系統(tǒng)的攝像頭app來(lái)拍照和錄制視頻拍照<manifest

...

>

<uses-feature

android:name="android.hardware.camera"

android:required="true"

/>

...

</manifest>使用默認(rèn)Intent開(kāi)始拍照static

final

int

REQUEST_IMAGE_CAPTURE

=

1;

private

void

dispatchTakePictureIntent()

{

Intent

takePictureIntent

=

new

Intent(MediaStore.ACTION_IMAGE_CAPTURE);

if

(takePictureIntent.resolveActivity(getPackageManager())

!=

null)

{

startActivityForResult(takePictureIntent,

REQUEST_IMAGE_CAPTURE);

}

}@Override

protected

void

onActivityResult(int

requestCode,

int

resultCode,

Intent

data)

{

if

(requestCode

==

REQUEST_IMAGE_CAPTURE

&&

resultCode

==

RESULT_OK)

{

Bundle

extras

=

data.getExtras();

Bitmap

imageBitmap

=

(Bitmap)

extras.get("data");

mImageView.setImageBitmap(imageBitmap);

}

}自定義保存相片圖片路徑<manifest

...>

<uses-permission

android:name="android.permission.WRITE_EXTERNAL_STORAGE"

/>

...

</manifest>static

final

int

REQUEST_TAKE_PHOTO

=

1;

private

void

dispatchTakePictureIntent()

{

Intent

takePictureIntent

=

new

Intent(MediaStore.ACTION_IMAGE_CAPTURE);

//

Ensure

that

there's

a

camera

activity

to

handle

the

intent

if

(takePictureIntent.resolveActivity(getPackageManager())

!=

null)

{

//

Create

the

File

where

the

photo

should

go

File

photoFile

=

null;

try

{

photoFile

=

createImageFile();

}

catch

(IOException

ex)

{

//

Error

occurred

while

creating

the

File

...

}

//

Continue

only

if

the

File

was

successfully

created

if

(photoFile

!=

null)

{

Uri

photoURI

=

FileProvider.getUriForFile(this,

"com.example.android.fileprovider",

photoFile);

takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,

photoURI);

startActivityForResult(takePictureIntent,

REQUEST_TAKE_PHOTO);

}

}

}

String

mCurrentPhotoPath;

private

File

createImageFile()

throws

IOException

{

//

Create

an

image

file

name

String

timeStamp

=

new

SimpleDateFormat("yyyyMMdd_HHmmss").format(new

Date());

String

imageFileName

=

"JPEG_"

+

timeStamp

+

"_";

File

storageDir

=

getExternalFilesDir(Environment.DIRECTORY_PICTURES);

File

image

=

File.createTempFile(

imageFileName,

/*

prefix

*/

".jpg",

/*

suffix

*/

storageDir

/*

directory

*/

);

//

Save

a

file:

path

for

use

with

ACTION_VIEW

intents

mCurrentPhotoPath

=

image.getAbsolutePath();

return

image;

}<application>

...

<provider

android:name="android.support.v4.content.FileProvider"

android:authorities="com.example.android.fileprovider"

android:exported="false"

android:grantUriPermissions="true">

<meta-data

android:name="android.support.FILE_PROVIDER_PATHS"

android:resource="@xml/file_paths"></meta-data>

</provider>

...

</application><?xml

version="1.0"

encoding="utf-8"?>

<paths

xmlns:android="/apk/res/android">

<external-path

name="my_images"

path="Android/data//files/Pictures"

/>

</paths>添加照片到相冊(cè)private

void

galleryAddPic()

{

Intent

mediaScanIntent

=

new

Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);

File

f

=

new

File(mCurrentPhotoPath);

try

{

MediaStore.Images.Media.insertImage(getContentResolver(),

f.getAbsolutePath(),

f.getName(),

null);

Log.d(TAG,

"galleryAddPic:

add

to

Media

Scanner

success");

}

catch

(FileNotFoundException

e)

{

e.printStackTrace();

Log.e(TAG,

"galleryAddPic:

add

to

Media

Scanner

failed");

}

Uri

contentUri

=

Uri.fromFile(f);

mediaScanIntent.setData(contentUri);

this.sendBroadcast(mediaScanIntent);

Toast.makeText(this,

"Add

to

Gallery

success",

Toast.LENGTH_SHORT).show();

}解碼縮放圖片private

void

setPic()

{

//

Get

the

dimensions

of

the

View

int

targetW

=

mImageView.getWidth();

int

targetH

=

mImageView.getHeight();

//

Get

the

dimensions

of

the

bitmap

BitmapFactory.Options

bmOptions

=

new

BitmapFactory.Options();

bmOptions.inJustDecodeBounds

=

true;

BitmapFactory.decodeFile(mCurrentPhotoPath,

bmOptions);

int

photoW

=

bmOptions.outWidth;

int

photoH

=

bmOptions.outHeight;

//

Determine

how

much

to

scale

down

the

image

int

scaleFactor

=

Math.min(photoW/targetW,

photoH/targetH);

//

Decode

the

image

file

into

a

Bitmap

sized

to

fill

the

View

bmOptions.inJustDecodeBounds

=

false;

bmOptions.inSampleSize

=

scaleFactor;

bmOptions.inPurgeable

=

true;

Bitmap

bitmap

=

BitmapFactory.decodeFile(mCurrentPhotoPath,

bmOptions);

mImageView.setImageBitmap(bitmap);

}錄像static

final

int

REQUEST_VIDEO_CAPTURE

=

1;

private

void

dispatchTakeVideoIntent()

{

Intent

takeVideoIntent

=

new

Intent(MediaStore.ACTION_VIDEO_CAPTURE);

if

(takeVideoIntent.resolveActivity(getPackageManager())

!=

null)

{

startActivityForResult(takeVideoIntent,

REQUEST_VIDEO_CAPTURE);

}

}@Override

protected

void

onActivityResult(int

requestCode,

int

resultCode,

Intent

intent)

{

if

(requestCode

==

REQUEST_VIDEO_CAPTURE

&&

resultCode

==

RESULT_OK)

{

Uri

videoUri

=

intent.getData();

Log.d(TAG,

"onActivityResult:

"

+

videoUri);

mVideoView.setVideoURI(videoUri);

mVideoView.requestFocus();

mVideoView.setOnPreparedListener(new

MediaPlayer.OnPreparedListener()

{

@Override

public

void

onPrepared(MediaPlayer

mp)

{

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論