如何获得android手机拍照后照片的android 图片存放目录录

后使用快捷导航没有帐号?
只需一步,快速开始
查看: 3960|回复: 6
在线时间14 小时经验值36 最后登录注册时间帖子阅读权限20UID4210531
小学生, 积分 36, 距离下一级还需 14 积分
该用户从未签到
G币36 最后登录注册时间
马上注册,结交更多机友,下载更多应用,让你轻松玩转手机。
已有帐号?   下载游戏和软件,请【】进入机锋市场!
我用手机里自带相机照相储存哪去去了,我要拷贝到电脑里找不到文件啊,急。。。谢谢指点
来机锋学学只能手机
在线时间328 小时经验值387 最后登录注册时间帖子阅读权限50UID1492322
大学专科, 积分 387, 距离下一级还需 13 积分
该用户从未签到
G币606 最后登录注册时间
SD卡的DCIM文件夹
在线时间14 小时经验值36 最后登录注册时间帖子阅读权限20UID4210531
小学生, 积分 36, 距离下一级还需 14 积分
该用户从未签到
G币36 最后登录注册时间
哪位大侠说下,万分感谢,还有怎么更改默认储存目录
来机锋学学只能手机
在线时间5 小时经验值10 最后登录注册时间帖子阅读权限10UID5230154
幼儿园, 积分 10, 距离下一级还需 5 积分
该用户从未签到
G币25 最后登录注册时间
金币啊..- - 支持个..
看蓝猫,学蓝猫,我有知识我自豪~!
在线时间28 小时经验值25 最后登录注册时间帖子阅读权限20UID5229368
小学生, 积分 25, 距离下一级还需 25 积分
该用户从未签到
G币32 最后登录注册时间
{:125_455:}学习!
defy新手,请多多指教!
在线时间35 小时经验值29 最后登录注册时间帖子阅读权限20UID1576302
小学生, 积分 29, 距离下一级还需 21 积分
该用户从未签到
G币376 最后登录注册时间
在线时间61 小时经验值372 最后登录注册时间帖子阅读权限50UID5288997
大学专科, 积分 372, 距离下一级还需 28 积分
TA的每日心情慵懒 08:43签到天数: 1 天[LV.1]初来乍到
G币339 最后登录注册时间
我的,以前是在dcim文件夹里,换了8G卡后(把原2G卡文件全部照搬了),照片不在这里了,也找不到了
Powered byAndroid应用中拍照后获取照片路径并上传的实例分享
作者:神神的蜗牛
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了Android应用中拍照后获取照片路径并上传的实例分享,文中使用MultipartEntityBuilder制作了一个简单的上传工具,需要的朋友可以参考下
Activity 中的代码,我只贴出重要的事件部分代码
public void doPhoto(View view)
destoryBimap();
String state = Environment.getExternalStorageState();
if (state.equals(Environment.MEDIA_MOUNTED)) {
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
startActivityForResult(intent, 1);
Toast.makeText(MainActivity.this, "没有SD卡", Toast.LENGTH_LONG).show();
protected void onActivityResult(int requestCode, int resultCode, Intent data)
Uri uri = data.getData();
if (uri != null) {
this.photo = BitmapFactory.decodeFile(uri.getPath());
if (this.photo == null) {
Bundle bundle = data.getExtras();
if (bundle != null) {
this.photo = (Bitmap) bundle.get("data");
Toast.makeText(MainActivity.this, "拍照失败", Toast.LENGTH_LONG).show();
FileOutputStream fileOutputStream =
// 获取 SD 卡根目录
String saveDir = Environment.getExternalStorageDirectory() + "/meitian_photos";
// 新建目录
File dir = new File(saveDir);
if (! dir.exists()) dir.mkdir();
// 生成文件名
SimpleDateFormat t = new SimpleDateFormat("yyyyMMddssSSS");
String filename = "MT" + (t.format(new Date())) + ".jpg";
// 新建文件
File file = new File(saveDir, filename);
// 打开文件输出流
fileOutputStream = new FileOutputStream(file);
// 生成图片文件
pressFormat.JPEG, 100, fileOutputStream);
// 相片的完整路径
this.picPath = file.getPath();
ImageView imageView = (ImageView) findViewById(R.id.showPhoto);
imageView.setImageBitmap(this.photo);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fileOutputStream != null) {
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
* 销毁图片文件
private void destoryBimap()
if (photo != null && ! photo.isRecycled()) {
photo.recycle();
Layout 布局页面
&LinearLayout xmlns:android="/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
&ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
&LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/doPhoto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginBottom="10dp"
android:text="拍照"
android:onClick="doPhoto"
android:id="@+id/showContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
&ImageView
android:id="@+id/showPhoto"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:scaleType="centerCrop"
android:src="@drawable/add"
android:layout_marginBottom="10dp"
&/LinearLayout&
&/ScrollView&
&/LinearLayout&
其中的上传工具类我们下面一起来看:
Android 发送HTTP GET POST 请求以及通过 MultipartEntityBuilder 上传文件
全部使用新的方式 MultipartEntityBuilder 来处理了。
httpmime-4.3.2.jar&&&
httpcore-4.3.1.jar&&
下载地址:http://hc.apache.org/downloads.cgi
有些镜像貌似打不开,页面上可以可以选择国内的 .cn 后缀的域名镜像服务器来下载
直接上代码了:
ZHttpRequset.java
package com.ai9475.
import org.apache.http.HttpE
import org.apache.http.HttpR
import org.apache.http.HttpS
import org.apache.http.client.HttpC
import org.apache.http.client.methods.HttpG
import org.apache.http.client.methods.HttpP
import org.apache.http.client.methods.HttpRequestB
import org.apache.http.entity.mime.HttpMultipartM
import org.apache.http.entity.mime.MultipartEntityB
import org.apache.http.impl.client.DefaultHttpC
import org.apache.http.params.BasicHttpP
import org.apache.http.params.HttpConnectionP
import org.apache.http.params.HttpP
import org.apache.http.protocol.HTTP;
import java.io.ByteArrayOutputS
import java.io.IOE
import java.io.InputS
import java.nio.charset.C
* Created by ZHOUZ on 14-2-3.
public class ZHttpRequest
public final String HTTP_GET = "GET";
public final String HTTP_POST = "POST";
* 当前请求的 URL
protected String url = "";
* HTTP 请求的类型
protected String requsetType = HTTP_GET;
* 连接请求的超时时间
protected int connectionTimeout = 5000;
* 读取远程数据的超时时间
protected int soTimeout = 10000;
* 服务端返回的状态码
protected int statusCode = -1;
* 当前链接的字符编码
protected String charset = HTTP.UTF_8;
* HTTP GET 请求管理器
protected HttpRequestBase httpRequest=
* HTTP 请求的配置参数
protected HttpParams httpParameters=
* HTTP 请求响应
protected HttpResponse httpResponse=
* HTTP 客户端连接管理器
protected HttpClient httpClient=
* HTTP POST 方式发送多段数据管理器
protected MultipartEntityBuilder multipartEntityBuilder=
* 绑定 HTTP 请求的事件监听器
protected OnHttpRequestListener onHttpRequestListener =
public ZHttpRequest(){}
public ZHttpRequest(OnHttpRequestListener listener) {
this.setOnHttpRequestListener(listener);
* 设置当前请求的链接
* @param url
public ZHttpRequest setUrl(String url)
this.url =
* 设置连接超时时间
* @param timeout 单位(毫秒),默认 5000
public ZHttpRequest setConnectionTimeout(int timeout)
this.connectionTimeout =
* 设置 socket 读取超时时间
* @param timeout 单位(毫秒),默认 10000
public ZHttpRequest setSoTimeout(int timeout)
this.soTimeout =
* 设置获取内容的编码格式
* @param charset 默认为 UTF-8
public ZHttpRequest setCharset(String charset)
this.charset =
* 获取当前 HTTP 请求的类型
public String getRequestType()
return this.requsetT
* 判断当前是否 HTTP GET 请求
public boolean isGet()
return this.requsetType == HTTP_GET;
* 判断当前是否 HTTP POST 请求
public boolean isPost()
return this.requsetType == HTTP_POST;
* 获取 HTTP 请求响应信息
public HttpResponse getHttpResponse()
return this.httpR
* 获取 HTTP 客户端连接管理器
public HttpClient getHttpClient()
return this.httpC
* 添加一条 HTTP 请求的 header 信息
* @param name
* @param value
public ZHttpRequest addHeader(String name, String value)
this.httpRequest.addHeader(name, value);
* 获取 HTTP GET 控制器
public HttpGet getHttpGet()
return (HttpGet) this.httpR
* 获取 HTTP POST 控制器
public HttpPost getHttpPost()
return (HttpPost) this.httpR
* 获取请求的状态码
public int getStatusCode()
return this.statusC
* 通过 GET 方式请求数据
* @param url
* @throws IOException
public String get(String url) throws Exception
this.requsetType = HTTP_GET;
// 设置当前请求的链接
this.setUrl(url);
// 新建 HTTP GET 请求
this.httpRequest = new HttpGet(this.url);
// 执行客户端请求
this.httpClientExecute();
// 监听服务端响应事件并返回服务端内容
return this.checkStatus();
* 获取 HTTP POST 多段数据提交管理器
public MultipartEntityBuilder getMultipartEntityBuilder()
if (this.multipartEntityBuilder == null) {
this.multipartEntityBuilder = MultipartEntityBuilder.create();
// 设置为浏览器兼容模式
multipartEntityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
// 设置请求的编码格式
multipartEntityBuilder.setCharset(Charset.forName(this.charset));
return this.multipartEntityB
* 配置完要 POST 提交的数据后, 执行该方法生成数据实体等待发送
public void buildPostEntity()
// 生成 HTTP POST 实体
HttpEntity httpEntity = this.multipartEntityBuilder.build();
this.getHttpPost().setEntity(httpEntity);
* 发送 POST 请求
* @param url
* @throws Exception
public String post(String url) throws Exception
this.requsetType = HTTP_POST;
// 设置当前请求的链接
this.setUrl(url);
// 新建 HTTP POST 请求
this.httpRequest = new HttpPost(this.url);
// 执行客户端请求
this.httpClientExecute();
// 监听服务端响应事件并返回服务端内容
return this.checkStatus();
* 执行 HTTP 请求
* @throws Exception
protected void httpClientExecute() throws Exception
// 配置 HTTP 请求参数
this.httpParameters = new BasicHttpParams();
this.httpParameters.setParameter("charset", this.charset);
// 设置 连接请求超时时间
HttpConnectionParams.setConnectionTimeout(this.httpParameters, this.connectionTimeout);
// 设置 socket 读取超时时间
HttpConnectionParams.setSoTimeout(this.httpParameters, this.soTimeout);
// 开启一个客户端 HTTP 请求
this.httpClient = new DefaultHttpClient(this.httpParameters);
// 启动 HTTP POST 请求执行前的事件监听回调操作(如: 自定义提交的数据字段或上传的文件等)
this.getOnHttpRequestListener().onRequest(this);
// 发送 HTTP 请求并获取服务端响应状态
this.httpResponse = this.httpClient.execute(this.httpRequest);
// 获取请求返回的状态码
this.statusCode = this.httpResponse.getStatusLine().getStatusCode();
* 读取服务端返回的输入流并转换成字符串返回
* @throws Exception
public String getInputStream() throws Exception
// 接收远程输入流
InputStream inStream = this.httpResponse.getEntity().getContent();
// 分段读取输入流数据
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int len = -1;
while ((len = inStream.read(buf)) != -1) {
baos.write(buf, 0, len);
// 数据接收完毕退出
inStream.close();
// 将数据转换为字符串保存
return new String(baos.toByteArray(), this.charset);
* 关闭连接管理器释放资源
protected void shutdownHttpClient()
if (this.httpClient != null && this.httpClient.getConnectionManager() != null) {
this.httpClient.getConnectionManager().shutdown();
* 监听服务端响应事件并返回服务端内容
* @throws Exception
protected String checkStatus() throws Exception
OnHttpRequestListener listener = this.getOnHttpRequestListener();
if (this.statusCode == HttpStatus.SC_OK) {
// 请求成功, 回调监听事件
content = listener.onSucceed(this.statusCode, this);
// 请求失败或其他, 回调监听事件
content = listener.onFailed(this.statusCode, this);
// 关闭连接管理器释放资源
this.shutdownHttpClient();
* HTTP 请求操作时的事件监听接口
public interface OnHttpRequestListener
* 初始化 HTTP GET 或 POST 请求之前的 header 信息配置 或 其他数据配置等操作
* @param request
* @throws Exception
public void onRequest(ZHttpRequest request) throws E
* 当 HTTP 请求响应成功时的回调方法
* @param statusCode 当前状态码
* @param request
* @return 返回请求获得的字符串内容
* @throws Exception
public String onSucceed(int statusCode, ZHttpRequest request) throws E
* 当 HTTP 请求响应失败时的回调方法
* @param statusCode 当前状态码
* @param request
* @return 返回请求失败的提示内容
* @throws Exception
public String onFailed(int statusCode, ZHttpRequest request) throws E
* 绑定 HTTP 请求的监听事件
* @param listener
public ZHttpRequest setOnHttpRequestListener(OnHttpRequestListener listener)
this.onHttpRequestListener =
* 获取已绑定过的 HTTP 请求监听事件
public OnHttpRequestListener getOnHttpRequestListener()
return this.onHttpRequestL
在 Activity 中的使用方法(这里我还是只写主体部分代码):
MainActivity.java
public void doClick(View view)
ZHttpRequest get = new ZHttpRequest();
.setCharset(HTTP.UTF_8)
.setConnectionTimeout(5000)
.setSoTimeout(5000);
get.setOnHttpRequestListener(new ZHttpRequest.OnHttpRequestListener() {
public void onRequest(ZHttpRequest request) throws Exception {
public String onSucceed(int statusCode, ZHttpRequest request) throws Exception {
return request.getInputStream();
public String onFailed(int statusCode, ZHttpRequest request) throws Exception {
return "GET 请求失败:statusCode "+ statusC
ZHttpRequest post = new ZHttpRequest();
.setCharset(HTTP.UTF_8)
.setConnectionTimeout(5000)
.setSoTimeout(10000);
post.setOnHttpRequestListener(new ZHttpRequest.OnHttpRequestListener() {
private String CHARSET = HTTP.UTF_8;
private ContentType TEXT_PLAIN = ContentType.create("text/plain", Charset.forName(CHARSET));
public void onRequest(ZHttpRequest request) throws Exception {
// 设置发送请求的 header 信息
request.addHeader("cookie", "abc=123;456=爱就是幸福;");
// 配置要 POST 的数据
MultipartEntityBuilder builder = request.getMultipartEntityBuilder();
builder.addTextBody("p1", "abc");
builder.addTextBody("p2", "中文", TEXT_PLAIN);
builder.addTextBody("p3", "abc中文cba", TEXT_PLAIN);
if (picPath != null && ! "".equals(picPath)) {
builder.addTextBody("pic", picPath);
builder.addBinaryBody("file", new File(picPath));
request.buildPostEntity();
public String onSucceed(int statusCode, ZHttpRequest request) throws Exception {
return request.getInputStream();
public String onFailed(int statusCode, ZHttpRequest request) throws Exception {
return "POST 请求失败:statusCode "+ statusC
TextView textView = (TextView) findViewById(R.id.showContent);
String content = "初始内容";
if (view.getId() == R.id.doGet) {
content = get.get("");
content = "GET数据:isGet: " + (get.isGet() ? "yes" : "no") + " =&" +
content = post.post("http://192.168.1.6/test.php");
content = "POST数据:isPost" + (post.isPost() ? "yes" : "no") + " =&" +
} catch (IOException e) {
content = "IO异常:" + e.getMessage();
} catch (Exception e) {
content = "异常:" + e.getMessage();
textView.setText(content);
其中 picPath 为 SD 卡中的图片路径 String 类型,我是直接拍照后进行上传用的
activity_main.xml
&LinearLayout xmlns:android="/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
&ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
&LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/doGet"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginBottom="10dp"
android:text="GET请求"
android:onClick="doClick"
android:id="@+id/doPost"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginBottom="10dp"
android:text="POST请求"
android:onClick="doClick"
android:id="@+id/doPhoto"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_marginBottom="10dp"
android:text="拍照"
android:onClick="doPhoto"
android:id="@+id/showContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
&ImageView
android:id="@+id/showPhoto"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:scaleType="centerCrop"
android:src="@drawable/add"
android:layout_marginBottom="10dp"
&/LinearLayout&
&/ScrollView&
&/LinearLayout&
至于服务端我用的 PHP ,只是简单的输出获取到的数据而已
echo 'GET:&br&'. "\n";
//print_r(array_map('urldecode', $_GET));
print_r($_GET);
echo '&br&'. "\n". 'POST:&br&'. "\n";
//print_r(array_map('urldecode', $_POST));
print_r($_POST);
echo '&br&'. "\n". 'FILES:&br&'. "\n";
print_r($_FILES);
echo '&br&'. "\n". 'COOKIES:&br&'. "\n";
print_r($_COOKIE);
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具[转载]Android开发&拍照、图片及保存照片技巧
本文主要讲解的是保存拍照后的图片到系统默认文件夹下,并在日后使用系统自带 图库 应用时可以方便的看到。
本文主要内容:
1、调用系统相机拍照并存储;
2、处理大图片防止内存溢出(OOM);
3、获取系统默认照片路径并保存;
4、刷新系统相册,解决图库不能立刻显示最新照片的问题;
5、图片裁剪;
6、图片大小及尺寸调整。
随着《证件照片助手》
这一工具类应用的开发和上线,个人的代码能力又得到了一些提高,积累了一些经验。现将用到的难点和一些小技巧分享给大家,望各位前辈批评指正!
调用系统相机,不用多说,网上已经有很多的例子了。当然,为了完整性,做再次说明:
首先,在要调用相机的代码位置,写上以下内容:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(new
File(AppConf.BUFFER_FILE)));
startActivityForResult(intent, requestCode_camera);
这里有几点需要注意:
1、MediaStore.ACTION_IMAGE_CAPTURE和MediaStore.EXTRA_OUTPUT是MediaStore类的常量,这个类是安卓系统提供的多媒体相关的类;
2、AppConf.BUFFER_FILE是调用系统相机拍照成功并经过用户确认后生成的照片的存储路径。当然,你也可以直接把这个路径定义到系统默认相册路径上。这里是为了应用需要,使用了临时的目录来存放照片。有关系统默认相册路径和后续处理,请直接往后看;
3、requestCode_camera是为了标识从系统相册返回的。
然后,在回调方法onActivityResult()中,处理系统相机返回的数据。
       
if (requestCode == requestCode_camera) {
           
              
BitmapFactory.Options options = new
BitmapFactory.Options();
               
options.inTempStorage = new byte[1024 * 1024 * 2];
               
options.inSampleSize = 2;
               
Bitmap bitmap = BitmapFactory.decodeFile(AppConf.BUFFER_FILE,
                       
               
if (bitmap != null) {
                   
ResizeActivity.bitmap =
                   
startActivity(new Intent(MenuActivity.this,
                           
ResizeActivity.class));
               
           
} catch (Exception e) {
               
e.printStackTrace();
           
       
这里,紫色文字部分是防止图片过大溢出的处理,使用了2MB的大小操作,这样避免了因图片过大造成OOM。灰色文字部分是本应用需要,可以忽略。
至此,我们就可以拿到用户刚刚拍照的照片的Bitmap对象了。
说到系统相册的默认路径,估计大家想到的应该是那个叫做&DCIM&的文件夹。这个一点都没错,我们可以直接用&/mnt/sdcard/DCIM&。可是,还有很多手机的路径是&/storage/sdcard0/DCIM&,特别是在4.1及以上的系统中。为了统一,可以用下面的方法来获取路径:
Environment.getExternalStorageDirectory() + File.separator +
Environment.DIRECTORY_DCIM
这样就能获取系统的照片文件夹了。
下面我们就将刚刚生成好的Bitmap对象保存到这个目录下:
   
    public
static void save(Bitmap bitmap, Context context, Activity activity)
        
// 调整到100*130
       
Matrix matrix = new Matrix();
       
matrix.postScale(100f / bitmap.getWidth(), 130f /
bitmap.getHeight());
       
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
               
bitmap.getHeight(), matrix, true);
      
int option = 100;
       
FileOutputStream photo =
       
File file = new File(AppConf.PHOTO_WRITE_PATH);
       
file.mkdir();
       
String str =
       
Date date =
       
SimpleDateFormat format = new
SimpleDateFormat(&yyyyMMddHHmmss&);
       
date = new Date(System.currentTimeMillis());
       
str = format.format(date);
       
fileName = AppConf.PHOTO_WRITE_PATH + File.separator
               
+ &ht_choosephoto_& + str +
       
           
photo = new FileOutputStream(fileName);
           
pressFormat.JPEG, option, photo);
           
photo.flush();
           
MediaStore.Images.Media.insertImage(context.getContentResolver(),
                   
fileName, new File(fileName).getName(),
                   
new File(fileName).getName());
           
Intent intent = new
Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
           
Uri uri = Uri.fromFile(new File(fileName));
           
intent.setData(uri);
           
activity.sendBroadcast(intent);
           
while (new File(fileName).length() / 1024
               
option -= 10;
               
photo = new FileOutputStream(fileName);
               
pressFormat.JPEG, option, photo);
               
photo.flush();
           
           
ResizeActivity.mhandler.sendEmptyMessage(0);
           
bitmap.recycle();
       
} catch (Exception e) {
           
e.printStackTrace();
       
    }
这个方法的功能有三个:
1、调整照片尺寸以符合2寸电子照片标准;
2、限制图片大小20KB以内;
3、保存图片;
4、刷新系统相册。
如果在程序中不去刷新系统相册的话,刚刚保存的图片是无法及时在图库应用中显示的。可使用快图这样的软件却能看得到,可是,我们不能指望每个用户都去安装第三方的图片浏览器。为了使程序更加好用,添加刷新的操作还是很有必要的。
这里我们做一个延伸思考:可以发现,刷新系统相册的操作实际上就是发送了系统内置的广播。也就是说,我们可以虚假发送系统的广播(尚未验证可用性)。所以在我们以后每次要发送这样的广播的时候,务必不要发错了,以免造成一些很奇怪的状况。
关于图片裁剪,首先看一下效果图:
<img src="/blog7style/images/common/sg_trans.gif" real_src ="/upload/apps/5173/screenshots/45021.JPG" WIDTH="223" HEIGHT="372"
ALT="[转载]Android开发&拍照、图片及保存照片技巧"
TITLE="[转载]Android开发&拍照、图片及保存照片技巧" />
效果是这样的:中间的调整部分实际上是一个ImageView,这个ImageView上面放置了一个只有白色边框的透明度图片,ImageView四周是由4个带有灰色背景的ImageView包裹的。这样一来,用户就可以清楚的分辨出白框内的图像就是裁剪后要保存的图片了。
思路是这样的:首先对整个屏幕进行截图,然后获取中间ImageView的坐标及控件大小,最后只要保存这个ImageView的截图就OK了。
具体实现是这样的:
&#160;&#160;&#160; int width
= cutWindow.getRight() - cutWindow.getLeft();
&#160;&#160;&#160; int height =
cutWindow.getBottom() - cutWindow.getTop();
&#160;&#160;&#160; // 截屏
&#160;&#160;&#160; View view =
getWindow().getDecorView();
&#160;&#160;&#160; Display
ResizeActivity.this.getWindowManager().getDefaultDisplay();
&#160;&#160;&#160;
view.layout(0, 0, display.getWidth(), display.getHeight());
&#160;&#160;&#160;
view.setDrawingCacheEnabled(true);
&#160;&#160;&#160; Bitmap
tempbmp = Bitmap.createBitmap(view.getDrawingCache());
&#160;&#160;&#160; // 裁剪
&#160;&#160;&#160; Bitmap bmp =
Bitmap.createBitmap(tempbmp, display.getWidth()/ 2 - width / 2 +
2,display.getHeight() / 2 - height/ 2 + 2, width - 4, height -
对于Bitmap对象bmp的处理还需注意:由于裁剪后得到的是ImageView的截图,因此四周的白框仍然是有的。我们需要减去1-2个像素来去掉四周的白框。
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。}

我要回帖

更多关于 android 图片存放目录 的文章

更多推荐

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

点击添加站长微信