动漫手机壁纸.docx
《动漫手机壁纸.docx》由会员分享,可在线阅读,更多相关《动漫手机壁纸.docx(6页珍藏版)》请在冰豆网上搜索。
![动漫手机壁纸.docx](https://file1.bdocx.com/fileroot1/2023-1/1/50a46dd6-e7de-4764-82e0-c763203d65e7/50a46dd6-e7de-4764-82e0-c763203d65e71.gif)
动漫手机壁纸
动漫手机壁纸
篇一:
Android-图片处理与动画
第四章图片处理
手机应用离不开图片。
图片不但可以给应用带来美观的界面,而且可以为用户提供丰富的功能和体验,在当下很难想象一个完全由文本组成的手机软件;而在开发过程中,对图片的加载,缓存,显示等处理又会直接影响整个项目的应能。
所以,在Android中对图片处理的重要性不言而喻。
本章中读者应该着重掌握如下内容:
(1)使用matrix对图片进行变换
(2)bitmap的操作
(3)图片异步加载框架的使用
4.1图片处理
4.1.1使用style和Theme创建样式与主题
如果我们平时注意观察了那些成熟的Android应用,就会发现它们大都使用一种统一的风格和样式贯穿整个项目,例如统一的背景色或背景图片,统一的标题栏,统一的按钮样式,统一的字体等等。
而这种“统一”就来自于style(样式)和Theme(主题)的使用
1.style
style从本质上讲就是一些属性的集合,例如:
layout_width,layout_height,textsize,textcolor等等,style将这些属性定义在xml文件中,供其他布局文件中的控件引用。
其角色类似于页面中的css,将样式单独抽离出来,方便修改和重用。
style的定义style定义在styles.xml中,创建在res/values/目录下,代码如下:
25sp
bold
上面代码中定义了一个名为itemTitle的样式,它包含textsize,textstyle两个属性。
style的使用
style可以在布局文件中通过名字来引用,代码如下:
style="@style/itemTitle"
android:
text="测试样式"
/>
2.Theme
Theme可以说和style是完全一样的,只不过Theme是针对Activity或整个项目的。
Theme的定义
Theme定义在theme.xml中,创建在res/values/目录下,代码如下:
#FFFFFFFF
@color/custom_background_color
上面代码中定义了一个名为RiverTheme的主题,它包含一个windowbackgroud属性。
这里继承了系统的theme.light,一般theme是继承的,这样可以对默认的风格不必重复定义。
本例定义了一个背景色。
这里背景色要单独声明,不能在item元素中直接写颜色值,会提示语法错误。
Theme的使用
Theme可以在manifest文件中通过名字来引用,代码如下:
android:
theme="@style/RiverTheme">
4.1.2matrix实现图片的几何操作
在Android中,若想对图片进行缩放,旋转等操作,就需要使用matrix类。
matrix的操作,总共分为translate(平移),rotate(旋转),scale(缩放)和skew(倾斜)四种。
下面的代码展示了实现缩放和旋转两种操作的步骤:
//根据图片资源创建相应的bitmap对象
mybmp=bitmapFactory.decodeResource(getResources(),R.drawable.im01);
//获取图片的原始宽高
bmpwidth=mybmp.getwidth();
bmpheight=mybmp.getheight();
//实例化matrix
matrixmatrix=newmatrix();
//设定matrix属性x,y缩放比例为1.5
matrix.postscale(1.5F,1.5F);
//顺时针旋转45度
matrix.postRotate(45.0F);
//根据matrix的设定产生新的bitmap对象
newbmp=bitmap.createbitmap(mybmp,0,0,bmpwidth,bmpheight,matrix,true);
在上面代码中,matrix的方法postscale和postRotate分别用来对图片的缩放和旋转进行设定。
缩放和旋转都围绕着一个中心点来进行,在默认情况下,中心点为(0,0),该点位于图片的物理中心。
实例bitmapDemo演示了对图片的旋转和缩放,如图4-1所示,拖动界面上方的拖动条(seekbar),可以顺时针旋转图片;点击下方按钮,可以放大图片。
图4-1图片的旋转和缩放
布局文件main.xml内容如下:
android:
layout_width="fill_parent"
android:
layout_height="fill_parent">
android:
id="@+id/seekbarId"
android:
layout_width="fill_parent"
android:
layout_height="wrap_content"
android:
layout_alignparentTop="true"/>
android:
id="@+id/imageview"
android:
layout_width="wrap_content"
android:
layout_height="wrap_content"
android:
src="@drawable/im01"
android:
layout_centerInparent="true"/>
android:
id="@+id/big"
android:
layout_width="wrap_content"
android:
layout_height="wrap_content"
android:
text="放大"
android:
layout_alignparentbottom="true"
android:
layout_centerhorizontal="true"
/>
bitmapDemoActivity.java代码如下:
packagecom.spl;
importandroid.app.Activity;
importandroid.graphics.bitmap;
importandroid.graphics.bitmapFactory;
importandroid.graphics.matrix;
importandroid.os.bundle;
importandroid.view.View;
importandroid.view.View.onclickListener;
importandroid.widget.button;
importandroid.widget.ImageView;
importandroid.widget.seekbar;
publicclassbitmapDemoActivityextendsActivity
{
ImageViewmyImageView;
bitmapmybmp,newbmp;
intbmpwidth,bmpheight;
seekbarseekbarRotate;
buttonbig;
floatrotAngle,scaleRate;
@override
publicvoidoncreate(bundlesavedInstancestate)
{
super.oncreate(savedInstancestate);
setcontentView(R.layout.main);
myImageView=(ImageView)findViewbyId(R.id.imageview);
//根据图片资源创建相应的bitmap对象
mybmp=bitmapFactory.decodeResource(getResources(),R.drawable.im01);
//获取图片的原始宽高
bmpwidth=mybmp.getwidth();
bmpheight=mybmp.getheight();
scaleRate=1.2F;
//实例化matrix
matrixmatrix=newmatrix();
//设定matrix属性x,y缩放比例为1.5
matrix.postscale(1.5F,1.5F);
//顺时针旋转45度
matrix.postRotate(45.0F);
//根据matrix的设定产生新的bitmap对象
newbmp=bitmap.createbitmap(mybmp,0,0,bmpwidth,bmpheight,matrix,true);seekbarRotate=(seekbar)findViewbyId(R.id.seekbarId);
seekbarRotate.setonseekbarchangeListener(onRotate);
big=(button)findViewbyId(R.id.big);
big.setonclickListener(bigclick);
}
//按钮点击监听器
privateonclickListenerbigclick=newonclickListener(){
@override
{publicvoidonclick(Viewarg0){matrixmatrix=newmatrix();//设定matrix属性x,y缩放比例为1.5matrix.postscale(scaleRate,scaleRate);newbmp=bitmap.createbitmap(mybmp,0,0,bmpwidth,bmpheight,matrix,true);myImageView.setImagebitmap(newbmp);bitmapDemoActivity.this.setTitle("scale:
"+scaleRate);scaleRate*=1.2F;//让放大比例持续增大};//拖动条监听器}privateseekbar.onseekbarchangeListeneronRotate=newseekbar.onseekbarchangeListener()
publicvoidonstopTrackingTouch(seekbarseekbar)
{
}
publicvoidonstartTrackingTouch(seekbarseekbar)
{
}
publicvoidonprogresschanged(seekbarseekbar,intprogress,
booleanfromuser)
{
//拖动过程中的事件处理
matrixm=newmatrix();
m.postRotate((float)progress*3.6F);//产生一定角度的旋转
newbmp=bitmap.createbitmap(mybmp,0,0,bmpwidth,bmpheight,m,true);myImageView.setImagebitmap(newbmp);
}
};
}
4.1.3bitmap的使用
bitmap称为点阵图像或位图图像,是由像素组成的,每个像素都可以看成颜色及透明度等信息的二进制编码单位,多个像素在一个平面上的二维排列就构成了bitmap。
bitmap是Android中处理图像最重要的类之一。
一张图片要想显示在Android应用中,必须先将图片文件的信息内容读取到bitmap中。
bitmap位于android.graphics包中,它不提供对外的构造方法,只能通过bitmapFactory的静态方法来实例化。
bitmapFactory提供了多个方法来获取bitmap实例,下面给大家逐一介绍:
1)从文件获取
mybmp=bitmapFactory.decodeFile(pathname);
mybmp=bitmapFactory.decodeFile(pathname,opts);
pathname为图片的绝对路径,一般为sDcard上的路径。
2)从资源中获取
mybmp=bitmapFactory.decodeResource(res,id);
篇二:
我的图片
240x320XX2kjpg
...浪漫的可爱卡通情侣图片240x...
290x400154kgif