安卓技术之两招让你学会Android图片拍摄及剪裁。在安卓设备中,要想实现图片的处理和裁剪有很多方法,用处也很广泛,北大青鸟武汉宏鹏鲁广校区的老师将和大家分享安卓图片的拍摄及裁剪方法,让大家用技术的力量去处理更多安卓开发中的实战问题。
步骤1、创建新的Android工程
使用Eclipse创建一个新的工程,并且在主界面的实现类中,先导入如下的包:
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
然后,在res/values目录中应用的定义字符串的文件strings.xml中,增加如下的定义:
Capture a picture to crop!
Picture
Launch Camera
我们将在接下来的界面中应用这些定义好的字符串资源。
步骤2、设计应用的界面
先,打开main.xml的主界面,我们使用Linearlayout布局格式,如下代码:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
并且在布局文件中添加一个文本标签,如下:
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/intro"
android:layout_margin="3dp"
android:textStyle="bold" />
接着再加一个button按钮和一个image控件,代码如下:
android:id="@+id/capture_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/capture" />
android:id="@+id/picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/picture"
android:layout_margin="5dp"
android:background="@drawable/pic_border" />
在这里,我们将通过手机捕捉的图片放在imageview控件中,并且设置了该imageview控件的文字提示内容,并且设置了背景颜色为drawable目录中指定的pic_border样式定义的颜色.其中pic_border.xml如下:
android:dither="true">
android:startColor="#99ffffff"
android:endColor="#99ffffff"
android:centerColor="#00000000"
android:angle="90" />
android:right="10dp" android:bottom="10dp" />
android:width="2dp"
android:color="#ccffffff"
/>
如果希望图片控件大小占满整个屏幕,则可以使用fill_parent属性而不是wrap_content,但这样要注意会减低图片的质量。这时我们运行下应用,可以看到现在的界面效果是如下图所示:
安卓技术之两招让你学会Android图片拍摄及剪裁的分享能够让更多的人了解到安卓开发的专业知识。北大青鸟武汉宏鹏鲁广校区的软件+3G课程能帮助学生了解到更多安卓开发的技术和项目开发的知识,在3G时代成就更多的梦想。
本文标题:安卓技术之两招让你学会Android图片拍摄及剪裁,责任编辑:宏鹏,来源:武汉北大青鸟鲁广校区栏目,于08-02发布于北大青鸟鲁广校区。安卓技术之两招让你学会Android图片拍摄及剪裁。在安卓设备中,要想实现图片的处理和裁剪有很多方法,用处也很广泛
预约将免费领取7天课程体验卡
只为您方便就学
专业老师24小时1对1学习指导
定制专属于你的专属学习方案
微信号:17740513250
微信号:17740513250