




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
【移動應(yīng)用開發(fā)技術(shù)】Android中視頻采集的示例分析
Camera基礎(chǔ)知識權(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來拍照和錄制視頻拍照<manifest
...
>
<uses-feature
android:name="android.hardware.camera"
android:required="true"
/>
...
</manifest>使用默認Intent開始拍照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>添加照片到相冊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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025至2030年中國黑白高線攝像機市場分析及競爭策略研究報告
- 2025至2030年中國銅箔網(wǎng)市場分析及競爭策略研究報告
- 2025至2030年中國輸送機護欄市場分析及競爭策略研究報告
- 2025至2030年中國苧麻服裝市場分析及競爭策略研究報告
- 2025至2030年中國組合電磁茶盤市場分析及競爭策略研究報告
- 2025至2030年中國石材幕墻市場分析及競爭策略研究報告
- 2025至2030年中國漂白印細斑馬紋短毛絨市場分析及競爭策略研究報告
- 2025至2030年中國水轉(zhuǎn)移貼花市場分析及競爭策略研究報告
- 2025至2030年中國木藝燈飾配件市場分析及競爭策略研究報告
- 2025至2030年中國推車式內(nèi)窺鏡顯像儀市場分析及競爭策略研究報告
- 2024年鹽城市大豐區(qū)事業(yè)單位招聘考試真題
- 2025年6月浙江省高考技術(shù)試卷真題
- 2024年山西煙草專賣局考試真題試卷及答案
- 有機化學(xué)(上)(中國藥科大學(xué))知到智慧樹期末考試答案題庫2025年中國藥科大學(xué)
- 重癥肌無力課件
- 廣州外語學(xué)校小升初數(shù)學(xué)試題
- 2024內(nèi)蒙古煤炭地質(zhì)勘查(集團)一一七有限公司招聘筆試參考題庫附帶答案詳解
- 信訪工作法治化培訓(xùn)講座
- 露天礦山新進員工安全培訓(xùn)
- 主播助理合同范本
- 四川省2024普通高校招生本科一批調(diào)檔線(理科)
評論
0/150
提交評論