日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

Training—Capturing Photos

發(fā)布時(shí)間:2025/4/16 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Training—Capturing Photos 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

閱讀:https://developer.android.com/training/camera/index.html

先學(xué)學(xué)怎么從相機(jī)獲取相片。

首先要有權(quán)限:

<manifest ... ><uses-feature android:name="android.hardware.camera" />... </manifest ... > private void dispatchTakePictureIntent(int actionCode) {Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);startActivityForResult(takePictureIntent, actionCode); } //查詢是否有程序能夠照相 public static boolean isIntentAvailable(Context context, String action) {final PackageManager packageManager = context.getPackageManager();final Intent intent = new Intent(action);List<ResolveInfo> list =packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);return list.size() > 0; } //獲取Bitmap并顯示 private void handleSmallCameraPhoto(Intent intent) {Bundle extras = intent.getExtras();mImageBitmap = (Bitmap) extras.get("data");mImageView.setImageBitmap(mImageBitmap); } //保存圖像 storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), getAlbumName() ); //或者用下面的目錄 storageDir = new File (Environment.getExternalStorageDirectory()+ PICTURES_DIR+ getAlbumName() );private File createImageFile() throws IOException {// Create an image file nameString timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());String imageFileName = JPEG_FILE_PREFIX + timeStamp + "_";File image = File.createTempFile(imageFileName, JPEG_FILE_SUFFIX, getAlbumDir());mCurrentPhotoPath = image.getAbsolutePath();return image; }

如果要向INTENT存放圖片數(shù)據(jù),用:

File f = createImageFile(); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));

The following example method demonstrates how to invoke the system's media scanner to add your photo to the Media Provider's database, making it available in the Android Gallery application and to other apps.

private void galleryAddPic() {Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);File f = new File(mCurrentPhotoPath);Uri contentUri = Uri.fromFile(f);mediaScanIntent.setData(contentUri);this.sendBroadcast(mediaScanIntent); }

下面展示了如何實(shí)現(xiàn)縮略圖功能(可減少內(nèi)存使用):

private void setPic() {// Get the dimensions of the Viewint targetW = mImageView.getWidth();int targetH = mImageView.getHeight();// Get the dimensions of the bitmapBitmapFactory.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 imageint scaleFactor = Math.min(photoW/targetW, photoH/targetH);// Decode the image file into a Bitmap sized to fill the ViewbmOptions.inJustDecodeBounds = false;bmOptions.inSampleSize = scaleFactor;bmOptions.inPurgeable = true;Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath, bmOptions);mImageView.setImageBitmap(bitmap); }

?官方接下來的內(nèi)容還展示了如何獲取錄下的視頻以及相機(jī)的控制,請(qǐng)自行查看。

?


官方還提供了一些基礎(chǔ)的組件讓你顯示圖片還有HTML:

https://developer.android.com/training/printing/index.html

?

?

?

?

?

?

?

?

?

轉(zhuǎn)載于:https://www.cnblogs.com/yutoulck/p/3407412.html

總結(jié)

以上是生活随笔為你收集整理的Training—Capturing Photos的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。