導航:首頁 > 操作系統 > android拍照截取

android拍照截取

發布時間:2022-05-13 04:44:49

① 如何調用android的拍照或本地相冊選取,然後再實現相片上傳伺服器

首先是拍照:使用Intent即可,

[java] view plainprint?
01.final String start = Environment.getExternalStorageState();
02.private static final String PHOTOPATH = "/photo/";
03.
04.if(start.equals(Environment.MEDIA_MOUNTED)){
05.Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
06.File file = new File(Environment.getExternalStorageDirectory()+PHOTOPATH);
07.if(!file.exists()){
08.file.mkdirs();
09.}
10.tempphontname = System.currentTimeMillis()+".jpg";
11.buffer.append(Environment.getExternalStorageDirectory()+PHOTOPATH).append(tempphontname);
12.intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(buffer.toString())));
13.startActivityForResult(intent, 1);
14.}
final String start = Environment.getExternalStorageState();
private static final String PHOTOPATH = "/photo/";

if(start.equals(Environment.MEDIA_MOUNTED)){
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory()+PHOTOPATH);
if(!file.exists()){
file.mkdirs();
}
tempphontname = System.currentTimeMillis()+".jpg";
buffer.append(Environment.getExternalStorageDirectory()+PHOTOPATH).append(tempphontname);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(buffer.toString())));
startActivityForResult(intent, 1);
}
其次是從本地相冊選:依舊是Intent.

如下代碼:

[java] view plainprint?
01.if(start.equals(Environment.MEDIA_MOUNTED)){
02. Intent getImage = new Intent(Intent.ACTION_GET_CONTENT);
03. getImage.addCategory(Intent.CATEGORY_OPENABLE);
04. getImage.setType("image/jpeg");
05. startActivityForResult(getImage, 0);
06.}
if(start.equals(Environment.MEDIA_MOUNTED)){
Intent getImage = new Intent(Intent.ACTION_GET_CONTENT);
getImage.addCategory(Intent.CATEGORY_OPENABLE);
getImage.setType("image/jpeg");
startActivityForResult(getImage, 0);
}

接下來是主要的:因為調用完系統的方法後,回返回到回調方法onActivityResult(int, int, Intent)中,

在裡面進行主要的照片上傳伺服器的操作,

見代碼:

[java] view plainprint?
01.@Override
02. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
03. ContentResolver resolver = getContentResolver();
04. if(requestCode==1)//
05. {
06. if(resultCode==Activity.RESULT_OK)
07. {
08. if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
09. {
10.ew Thread(new Runnable()
11. {
12. @Override
13. public void run() {
14.//進行上傳操作
15.}
16.}.start();
轉載

② android 怎麼裁剪drawable

可使用ScaleType來指定drawable的縮放方式,來實現裁剪效果。

ImageView的Scaletype決定了圖片在View上顯示時的樣子,如進行何種比例的縮放,及顯示圖片的整體還是部分,等等。
設置的方式包括:
1. 在layout xml中定義android:scaleType="CENTER"
2. 或在代碼中調用imageView.setScaleType(ImageView.ScaleType.CENTER);

Scaletype的取值說明:
1. SetScaleType(ImageView.ScaleType.CENTER);
按圖片的原來size居中顯示,當圖片長/寬超過View的長/寬,則截取圖片的居中部分顯示

2. SetScaleType(ImageView.ScaleType.CENTER_CROP);

按比例擴大圖片的size居中顯示,使得圖片長(寬)等於或大於View的長(寬)

3. setScaleType(ImageView.ScaleType.CENTER_INSIDE);
將圖片的內容完整居中顯示,通過按比例縮小或原來的size使得圖片長/寬等於或小於View的長/寬

4. setScaleType(ImageView.ScaleType.FIT_CENTER);

把圖片按比例擴大/縮小到View的寬度,居中顯示

5. FIT_START, FIT_END在圖片縮放效果上與FIT_CENTER一樣,只是顯示的位置不同,FIT_START是置於頂部,FIT_CENTER居中,FIT_END置於底部。
在此就不給出示例了。

6. FIT_XY
不按比例縮放圖片,目標是把圖片塞滿整個View。

③ android怎麼拍照並獲取照片

點擊拍照鍵 就會自動拍照並保存了

④ android 拍照獲取照片的文字,技術點是啥呀

這其實跟android沒有多大關系,拍照識別是單獨的一項技術,但是android也有自己的識別包名字叫做:android-ocr 圖片文字識別技術相關包,大體的原理就是,先將照片轉換為黑白,然後進行像素點識別,就跟識別車牌的原理是一樣的

⑤ 為啥android拍照後的裁剪界面閃了一下就消失了

步驟:點擊按鈕,彈出對話框,選擇拍照或者從相冊選擇圖片,並且保存到SD卡中,並且顯示在Imageview中
首先最終結果存在了imageUri中,但從拍照Intent到裁剪Intent之間結果是怎麼傳的呢?估計是通過Intent中的data來傳的,當數據過大,即超過1M時就崩了!!!!所以我們要想辦法分離這個過程,將中間數據先暫存一下放在imageUri ,然後再調裁剪Intent,最後把結果存在imageCropUri 中。
這樣就完美解決拍照裁剪圖片完成之後崩潰問題。

⑥ 安卓智能手機有自拍截圖功能嗎

肯定有啦,不過需要ROOT許可權然後安裝個截屏軟體就可以任意截屏了!

⑦ 有人知道怎麼禁止android系統 拍照和截屏么

這個啊,最簡單的是拆掉攝像頭,否則軟體層面,如果你不是個改系統內核的高手,很難做到軟體層阻止訪問攝像頭

⑧ 在android開發中,拍照後的圖片進行剪切後,怎麼保存呢

流,給你一個保存的方法
你應該是拍照以後再onActivityResult中回去圖片 再進行操作 得到最終的bitmap 在用下面的方法保存指定圖片的路徑、名稱保存。

// 保存拍攝的照片到手機的sd卡
private void SavePicInLocal(Bitmap bitmap) {
FileOutputStream fos = null;
BufferedOutputStream bos = null;
ByteArrayOutputStream baos = null; // 位元組數組輸出流
try {
baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] byteArray = baos.toByteArray();// 位元組數組輸出流轉換成位元組數組
picName = (list.size() + 1) < 10 ? memberInfoID + "-0"
+ (list.size() + 1) + ".jpg" : memberInfoID + "-"
+ (list.size() + 1) + ".jpg";
File file = new File(PHOTO_DIR, picName);
// 將位元組數組寫入到剛創建的圖片文件中
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos);
bos.write(byteArray);

} catch (Exception e) {
e.printStackTrace();

} finally {
if (baos != null) {
try {
baos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (bos != null) {
try {
bos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}

}

}
這個保存的是縮略以後的 有50k左右,

⑨ android 拍照,剪切,上傳頭像

Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
intent.putExtra("crop", "true"); // 裁剪
intent.putExtra("aspectX", 5);// 裁剪框比例
intent.putExtra("aspectY", 4);
intent.putExtra("outputX", 500);// 輸出圖片大小
intent.putExtra("outputY", 400);
intent.putExtra("outputFormat",
Bitmap.CompressFormat.JPEG.toString());
intent.putExtra("return-data", false);
intent.putExtra(MediaStore.EXTRA_OUTPUT, photoUri);
intent.putExtra("noFaceDetection", false); // no face detection
startActivityForResult(intent, requestCode);

⑩ android拍照圖片裁剪的問題

在裁剪代碼執行之前加上這幾句試試

try {
Runtime.getRuntime().exec("chmod 777 " + file.getAbsolutePath());

} catch (IOException e) {

e.printStackTrace();
}

閱讀全文

與android拍照截取相關的資料

熱點內容
梯形圖是編譯還是解釋執行 瀏覽:471
錄屏好用的app哪個好用 瀏覽:635
一念逍遙新伺服器怎麼看 瀏覽:90
移動app的信用充話費在哪裡 瀏覽:500
單片機接感測器 瀏覽:72
免費pdf工具 瀏覽:380
pdf加密一機一碼 瀏覽:600
怎麼把百度雲資源壓縮 瀏覽:456
不會數學英語如何編程 瀏覽:88
如何能知道網站伺服器地址 瀏覽:648
程序員月薪5萬難嗎 瀏覽:138
如何評價程序員 瀏覽:803
雲虛機和伺服器的區別 瀏覽:403
廣西柳州壓縮機廠 瀏覽:639
arm開發編譯器 瀏覽:833
51單片機的核心 瀏覽:746
看電視直播是哪個app 瀏覽:958
將c源程序編譯成目標文件 瀏覽:787
再要你命3000pdf 瀏覽:558
ai軟體解壓軟體怎麼解壓 瀏覽:520