下載本文檔
版權(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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 樁基礎(chǔ)施工合同范本
- 兩人合作經(jīng)營(yíng)業(yè)務(wù)合同樣本
- 個(gè)人投資合伙合同范本
- 個(gè)人房產(chǎn)抵押借款協(xié)議合同
- 親朋好友合伙購(gòu)房合同范例
- 2025版建筑工程施工總承包合同
- 個(gè)人租房合同格式及模板
- 個(gè)人租賃住宅合同范本解析
- 上海商業(yè)地產(chǎn)租賃合同范本
- 上海市租客與房東合同范本
- (正式版)JBT 11270-2024 立體倉(cāng)庫(kù)組合式鋼結(jié)構(gòu)貨架技術(shù)規(guī)范
- DB11∕T 2035-2022 供暖民用建筑室溫?zé)o線采集系統(tǒng)技術(shù)要求
- 《復(fù)旦大學(xué)》課件
- 針灸與按摩綜合療法
- 煤礦井下安全避險(xiǎn)六大系統(tǒng)建設(shè)完善基本規(guī)范
- Photoshop 2022從入門(mén)到精通
- T-GDWJ 013-2022 廣東省健康醫(yī)療數(shù)據(jù)安全分類(lèi)分級(jí)管理技術(shù)規(guī)范
- 校本課程生活中的化學(xué)
- DB43-T 2775-2023 花櫚木播種育苗技術(shù)規(guī)程
- 《我的家族史》課件
- 高空作業(yè)安全方案及應(yīng)急預(yù)案
評(píng)論
0/150
提交評(píng)論