照相机一拍就出照片拍了不存储照片怎么调

Android 照相机拍摄照片,压缩后储存于SD卡
一般相机拍摄的照片大小为3-4M左右,这里因为需要完成将拍摄好的照片上传到服务器功能,所以需要将得到的照片进行压缩。这里演示就直接存放在SD卡中。
网上搜索了不少资料,得知可以使用:inSampleSize 设置图片的缩放比例。
但是,这里需要注意:
1)inJustDecodeBounds = 需要先设置为真,表示只获得图片的资料信息。如果此时检验bitmap会发现bitmap==
2)如果需要加载图片的时候,必须重新设置inJustDecodeBounds =
一、实现图片压缩(网上看到别人的,自己稍微修改了一下):
//压缩图片尺寸
public Bitmap compressBySize(String pathName, int targetWidth,
int targetHeight) {
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds =// 不去真的解析图片,只是获取图片的头部信息,包含宽高等;
Bitmap bitmap = BitmapFactory.decodeFile(pathName, opts);
// 得到图片的宽度、高度;
float imgWidth = opts.outW
float imgHeight = opts.outH
// 分别计算图片宽度、高度与目标宽度、高度的比例;取大于等于该比例的最小整数;
int widthRatio = (int) Math.ceil(imgWidth / (float) targetWidth);
int heightRatio = (int) Math.ceil(imgHeight / (float) targetHeight);
opts.inSampleSize = 1;
if (widthRatio & 1 || widthRatio & 1) {
if (widthRatio & heightRatio) {
opts.inSampleSize = widthR
opts.inSampleSize = heightR
//设置好缩放比例后,加载图片进内容;
opts.inJustDecodeBounds =
bitmap = BitmapFactory.decodeFile(pathName, opts);
二、将压缩后的图片存储于SD卡:
//存储进SD卡
public void saveFile(Bitmap bm, String fileName) throws Exception {
File dirFile = new File(fileName);
//检测图片是否存在
if(dirFile.exists()){
dirFile.delete();
//删除原图片
File myCaptureFile = new File(fileName);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
//100表示不进行压缩,70表示压缩率为30%
bm.pressFormat.JPEG, 100, bos);
bos.flush();
bos.close();
这里注意,由于需要写SD卡,要添加一个权限:
三、附上一个完整的小Demo:
1)MainActivity.java
package com.face.
import java.io.BufferedOutputS
import java.io.F
import java.io.FileOutputS
import android.app.A
import android.graphics.B
import android.graphics.BitmapF
import android.os.B
import android.view.M
import android.view.MenuI
public class MainActivity extends Activity {
//照片保存地址
private static final String FILE_PATH = /sdcard/gone.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//压缩图片
Bitmap bitmap = compressBySize(FILE_PATH,150,200);
//保存图片
saveFile(bitmap, FILE_PATH);
} catch (Exception e) {
e.printStackTrace();
//压缩图片尺寸
public Bitmap compressBySize(String pathName, int targetWidth,
int targetHeight) {
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds =// 不去真的解析图片,只是获取图片的头部信息,包含宽高等;
Bitmap bitmap = BitmapFactory.decodeFile(pathName, opts);
// 得到图片的宽度、高度;
float imgWidth = opts.outW
float imgHeight = opts.outH
// 分别计算图片宽度、高度与目标宽度、高度的比例;取大于等于该比例的最小整数;
int widthRatio = (int) Math.ceil(imgWidth / (float) targetWidth);
int heightRatio = (int) Math.ceil(imgHeight / (float) targetHeight);
opts.inSampleSize = 1;
if (widthRatio & 1 || widthRatio & 1) {
if (widthRatio & heightRatio) {
opts.inSampleSize = widthR
opts.inSampleSize = heightR
//设置好缩放比例后,加载图片进内容;
opts.inJustDecodeBounds =
bitmap = BitmapFactory.decodeFile(pathName, opts);
//存储进SD卡
public void saveFile(Bitmap bm, String fileName) throws Exception {
File dirFile = new File(fileName);
//检测图片是否存在
if(dirFile.exists()){
dirFile.delete();
//删除原图片
File myCaptureFile = new File(fileName);
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
//100表示不进行压缩,70表示压缩率为30%
bm.pressFormat.JPEG, 100, bos);
bos.flush();
bos.close();
public boolean onCreateOptionsMenu(Menu menu) {
// I this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return super.onOptionsItemSelected(item);
2)mainfest
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'相机存储卡内存不足显示不了照片拍不了照片怎么办_百度知道&主题:不是本机拍的照片拷到存储卡中怎样才能在相机上打开?
泡网分: 26.602
注册: 2004年08月
本人数码相机是尼康,一直以来白平衡感觉不是特别准,现在网上看到一幅照片,白平衡非常漂亮,想把它拷到存储卡中,用来自定义白平衡,但是相机不能打开或者看不到,请问一下高手有什么方法解决吗?先谢谢啦!
作者相关热贴:
微信扫一扫分享
&浏览:1796&&回帖:21 &&
泡网分: 26.602
注册: 2004年08月
原文由 jsun1971 在 15:20发表
把照片名字改成跟你的尼康机器拍的照片名字同一连续序号就OK了。 这种情况试过,不行
泡网分: 15.16
注册: 2006年12月
白平衡是这样玩的啊~~& &手拿相机核桃中。。。
泡网分: 3.653
帖子: 1546
注册: 2011年04月
把照片名字改成跟你的尼康机器拍的照片名字同一连续序号就OK了。
泡网分: 11.587
帖子: 2747
注册: 2009年07月
可以试一下从以下两方面努力&
1. 改文件名 符合NIKON机器的连贯照片编号
2. 用光影改EXIF 改成NIKON CORPORATION 机器型号也要改
泡网分: 26.602
注册: 2004年08月
还有朋友吗,介绍一下经验!
泡网分: 26.602
注册: 2004年08月
还是谢谢各位赐教,不管怎样,都是学习!
泡网分: 4.167
注册: 2010年08月
虽然不赞成这么干,但还是很佩服楼主的想象力……
先在PS里打开一个自己拍的照片,然后把要拷贝的照片粘贴上去,这样照片信息应该还是原来自己照片的信息,也许相机可以读出来。
泡网分: 15.554
帖子: 2299
注册: 2008年08月
原文由 404nh 在 09:23发表
用别人照片定义白平衡...
你这不刻舟求剑么
泡网分: 25.973
帖子: 1724
注册: 2004年02月
nikon还能这么自定义白平衡?
canon倒是可以利用已拍摄照片这么干
泡网分: 2.356
注册: 2011年05月
居然这么学习白平衡。。。
拜服。。。
泡网分: 14.825
注册: 2007年07月
别说别的相机拍的照片了,就连本机拍的照片我ps了几下再拷回去都不显示了 --@
泡网分: 18.286
帖子: 1312
注册: 2007年02月
原文由 llj6618 在 09:52发表
终于见到了无忌最蛋疼的主。。。
泡网分: 51.902
帖子: 12989
注册: 2003年12月
原文由 duoduobear 在 10:12发表
佳能相机上好像存储卡上的图都能播放. Nikon的不行吗? 我试过,用尼康相机拍摄的jpg照片,在佳能、索尼的机器上都能浏览
反之不行:)
泡网分: 11.023
注册: 2010年05月
用nikon相机对着网上照片保证1:1比例翻拍一张,注意曝光及白平衡!
Canon论坛版主
泡网分: 78.603
帖子: 14218
注册: 2003年10月
佳能相机上好像存储卡上的图都能播放. Nikon的不行吗?
泡网分: 13.77
注册: 2007年12月
终于见到了无忌最蛋疼的主。。。
泡网分: 3.307
注册: 2011年04月
没准那幅照片是全白的呢?
泡网分: 4.864
注册: 2010年05月
可以采用灰卡、白纸等来定义照相机的白平衡
泡网分: 26.602
注册: 2004年08月
这也是一个方法呀。
泡网分: 37.49
帖子: 14527
注册: 2007年09月
泡网分: 8.121
注册: 2009年09月
用别人照片定义白平衡...
你这不刻舟求剑么
&版权所有:&&桂ICP备号&增值电信业务经营许可证怎么调整数码相机的照片保存模式,是模式不是格式!_百度知道}

我要回帖

更多关于 照相机存储卡 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信