1. 9.png格式的图片是安卓平台在png图片的基础上新创的格式。
它是由9个补丁(patch)组成的png,命名为 .9.png
与传统的png格式图片相比, 9.png 格式图片在图片四周有一圈一个像素点组成的边沿,该边沿用于对图片的可扩展区和内容显示区进行定义。
android会自动将.9.png的文件当做 9 patch文件来处理,9.png的文件就是一个png文件,其特殊之处在于周围一圈的框框由 0x00000000或者 0xffffffff 组成,
即有一圈黑白框,黑框所框住的地方是会被resize的,另外的4个角不会被resize, 而上下左右的四块,会被单向resize。
这对于一些按钮的png十分有好处,可以保持四周的圆角尺寸不变,而中心放大。
9.png图片的四周与普通的png图片相比多了一个像素位的白色区域,该区域只有在图片被还原和制造的时候才能看到,当打包后无法看见,并且图片的总像素会缩小2个像素,
比如23x23像素的9.png图片被打包后会变成21x21像素。
典型的例子是四个角是弧形的按钮图片,被拉伸时要保持弧形角不被拉伸,可设置四个圆角内侧的4条线拉伸,这样会保持中间内部的图像形状不变化,相对位置也不偏移。
这样图片被分成了9个部分,所以叫nine patch。\
2.android\tools目录中有一个draw9patch.bat,即画黑边工具,draw9patch.bat的使用方法是,打开一个普通的png图,然后将四周的中心用鼠标点上。再保存。
在右边可以看到缩放后的效果。
{注意,对于从别人apk中破解9.png的时候,android编译器已经将9.png的边框去掉了,所以还要再使用draw9patch.bat自己整一下。}
选中show patches,左侧黑色边线对应的绿色区域是上下拉伸的区域,上侧黑色边线对应的绿色区域是左右拉伸的区域。
被拉伸的区域贯穿上下或左右,不能实现只拉伸内部一块区域。
右键,或shift+左键清除黑线。
从apk文件中解压得到的.9.png,是已经去掉了黑边了的。在打包成apk时,.9.png中的空白像素被去掉了。可能这些信息被记录到了包的另外的地方。
draw9patch右侧的显示表示上下拉伸,左右拉伸,上下左右同时拉伸时的效果,同时还可以看到内容区域默认是整个图片。但是实际情况可能是当不设置内容区域时,
4.A NinePatchDrawable graphic is a stretchable bitmap image, which Android will automatically resize to accommodate the contents of the View
in which you have placed it as the background.
NinePatchDrawable 的特性是在它作为background时展现的。
If a View object sets the NinePatch as its background and then specifies the View's text, it will stretch itself so that all the text fits inside only
the area designated by the right and bottom lines (if included).
同时,它的内容区域是为视图的文本内容准备的。
Tools > Draw 9-patch中查找更多介绍。
http://developer.android.com/guide/developing/tools/draw9patch.html
1.使用InputStream inputStream = context.getResources().openRawResource(resId);读取在res\raw中的a.html时,报
WARN/ResourceType(406): getEntry failing because entryIndex 2 is beyond type entryCount 2,
修改为a.data后读取成功。
2.
Drawable,ColorMatrix
1.在android工程中,图片放在res\drawable*\中,类型有 *.png,*.9.png,*.xml。
Drawable的子类有StateListDrawable,NinePatchDrawable,
2.selector标签的xml文件,组合了drawable和state:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/icon2" />
<item android:state_enabled="true" android:state_pressed="true" android:drawable="@drawable/icon3" />
<item android:state_enabled="true" android:state_pressed="false" android:drawable="@drawable/icon1" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/icon3" />
<item android:state_window_focused="false" android:drawable="@drawable/icon1" />
</selector>
对应的java类是StateListDrawable:
StateListDrawable stateListDrawable = new StateListDrawable();
// View.PRESSED_ENABLED_STATE_SET
stateListDrawable.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, pressed_drawable);
// View.ENABLED_FOCUSED_STATE_SET
stateListDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }, selected_drawable);
// View.ENABLED_STATE_SET
stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, selected_drawable);
// View.FOCUSED_STATE_SET
stateListDrawable.addState(new int[] { android.R.attr.state_focused }, selected_drawable);
// View.WINDOW_FOCUSED_STATE_SET
stateListDrawable.addState(new int[] { android.R.attr.state_window_focused }, selected_drawable);
// View.EMPTY_STATE_SET
stateListDrawable.addState(new int[] {}, normal_drawable);
表示unfocused在android.R.attr.state_focused加-号。
部分view没有selected效果,只有radioButton等有该效果。
3.android不建议使用内部的图片资源,想使用最好拷贝一份使用。
Warning: Because these resources can change between platform versions, you should not reference these icons using the Android platform resource IDs
(i.e. menu icons underandroid.R.drawable).
If you want to use any icons or other internal drawable resources, you should store a local copy of those icons or drawables in your application resources,
then reference the local copy from your application code. In that way, you can maintain control over the appearance of your icons,
even if the system's copy changes. Note that the grid below is not intended to be complete.
在D:\android-sdk_r10-windows\platforms\android-8\data\res中可以找到。
http://www.rexsee.com
http://www.itbinary.com/art/14/167.html
http://www.apkbus.com/forum.php?mod=viewthread&tid=2276&extra=page%3D1
4.Android图片处理(Matrix,ColorMatrix)
http://www.cnblogs.com/leon19870907/articles/1978065.html
它是由9个补丁(patch)组成的png,命名为 .9.png
与传统的png格式图片相比, 9.png 格式图片在图片四周有一圈一个像素点组成的边沿,该边沿用于对图片的可扩展区和内容显示区进行定义。
android会自动将.9.png的文件当做 9 patch文件来处理,9.png的文件就是一个png文件,其特殊之处在于周围一圈的框框由 0x00000000或者 0xffffffff 组成,
即有一圈黑白框,黑框所框住的地方是会被resize的,另外的4个角不会被resize, 而上下左右的四块,会被单向resize。
这对于一些按钮的png十分有好处,可以保持四周的圆角尺寸不变,而中心放大。
9.png图片的四周与普通的png图片相比多了一个像素位的白色区域,该区域只有在图片被还原和制造的时候才能看到,当打包后无法看见,并且图片的总像素会缩小2个像素,
比如23x23像素的9.png图片被打包后会变成21x21像素。
典型的例子是四个角是弧形的按钮图片,被拉伸时要保持弧形角不被拉伸,可设置四个圆角内侧的4条线拉伸,这样会保持中间内部的图像形状不变化,相对位置也不偏移。
这样图片被分成了9个部分,所以叫nine patch。\
指定颜色值变化范围比较小的区域为伸缩区域来防止图片伸缩变形。内容区域一般设置为小于等于伸缩区域。
如果res/drawable目录中的9.png中没有黑线,eclipse会报错。
2.android\tools目录中有一个draw9patch.bat,即画黑边工具,draw9patch.bat的使用方法是,打开一个普通的png图,然后将四周的中心用鼠标点上。再保存。
在右边可以看到缩放后的效果。
{注意,对于从别人apk中破解9.png的时候,android编译器已经将9.png的边框去掉了,所以还要再使用draw9patch.bat自己整一下。}
选中show patches,左侧黑色边线对应的绿色区域是上下拉伸的区域,上侧黑色边线对应的绿色区域是左右拉伸的区域。
被拉伸的区域贯穿上下或左右,不能实现只拉伸内部一块区域。
右键,或shift+左键清除黑线。
从apk文件中解压得到的.9.png,是已经去掉了黑边了的。在打包成apk时,.9.png中的空白像素被去掉了。可能这些信息被记录到了包的另外的地方。
draw9patch右侧的显示表示上下拉伸,左右拉伸,上下左右同时拉伸时的效果,同时还可以看到内容区域默认是整个图片。但是实际情况可能是当不设置内容区域时,
NinePatch图片使用的就是拉伸区域作为内容区域,而不是NinePatch编辑器中指示的图片全部区域。
3.GradientDrawable 梯度绘图,渐变绘图
可以把它设置给窗口等对象的背景,实现渐变效果。
4.A NinePatchDrawable graphic is a stretchable bitmap image, which Android will automatically resize to accommodate the contents of the View
in which you have placed it as the background.
NinePatchDrawable 的特性是在它作为background时展现的。
If a View object sets the NinePatch as its background and then specifies the View's text, it will stretch itself so that all the text fits inside only
the area designated by the right and bottom lines (if included).
同时,它的内容区域是为视图的文本内容准备的。
Tools > Draw 9-patch中查找更多介绍。
http://developer.android.com/guide/developing/tools/draw9patch.html
1.使用InputStream inputStream = context.getResources().openRawResource(resId);读取在res\raw中的a.html时,报
WARN/ResourceType(406): getEntry failing because entryIndex 2 is beyond type entryCount 2,
修改为a.data后读取成功。
2.
Drawable,ColorMatrix
1.在android工程中,图片放在res\drawable*\中,类型有 *.png,*.9.png,*.xml。
Drawable的子类有StateListDrawable,NinePatchDrawable,
2.selector标签的xml文件,组合了drawable和state:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/icon2" />
<item android:state_enabled="true" android:state_pressed="true" android:drawable="@drawable/icon3" />
<item android:state_enabled="true" android:state_pressed="false" android:drawable="@drawable/icon1" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/icon3" />
<item android:state_window_focused="false" android:drawable="@drawable/icon1" />
</selector>
对应的java类是StateListDrawable:
StateListDrawable stateListDrawable = new StateListDrawable();
// View.PRESSED_ENABLED_STATE_SET
stateListDrawable.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, pressed_drawable);
// View.ENABLED_FOCUSED_STATE_SET
stateListDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }, selected_drawable);
// View.ENABLED_STATE_SET
stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, selected_drawable);
// View.FOCUSED_STATE_SET
stateListDrawable.addState(new int[] { android.R.attr.state_focused }, selected_drawable);
// View.WINDOW_FOCUSED_STATE_SET
stateListDrawable.addState(new int[] { android.R.attr.state_window_focused }, selected_drawable);
// View.EMPTY_STATE_SET
stateListDrawable.addState(new int[] {}, normal_drawable);
表示unfocused在android.R.attr.state_focused加-号。
部分view没有selected效果,只有radioButton等有该效果。
3.android不建议使用内部的图片资源,想使用最好拷贝一份使用。
Warning: Because these resources can change between platform versions, you should not reference these icons using the Android platform resource IDs
(i.e. menu icons underandroid.R.drawable).
If you want to use any icons or other internal drawable resources, you should store a local copy of those icons or drawables in your application resources,
then reference the local copy from your application code. In that way, you can maintain control over the appearance of your icons,
even if the system's copy changes. Note that the grid below is not intended to be complete.
在D:\android-sdk_r10-windows\platforms\android-8\data\res中可以找到。
http://www.rexsee.com
http://www.itbinary.com/art/14/167.html
http://www.apkbus.com/forum.php?mod=viewthread&tid=2276&extra=page%3D1
4.Android图片处理(Matrix,ColorMatrix)
http://www.cnblogs.com/leon19870907/articles/1978065.html