4. 位图缩放
(1)将一个位图按照需求重画一遍,画后的位图就是我们需要的了,与位图的显示几乎一样:(Bitmapbitmap,Rectsrc,Rectdst,Paintpaint)。
(2)在原有位图的基础上,缩放原位图,创建一个新的位图:CreateBitmap(Bitmap source, int x, int y, int width, int height, Matrix m, boolean filter)
(3)借助Canvas的(float sx, float sy) (Preconcat the current matrix with the specified scale.),不过要注意此时整个画布都缩放了。
(4)借助Matrix:
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pic180);Matrix matrix=new Matrix();matrix.postScale(0.2f, 0.2f);Bitmap dstbmp=Bitmap.createBitmap(bmp,0,0,bmp.getWidth(),bmp.getHeight(),matrix,true);canvas.drawColor(Color.BLACK);canvas.drawBitmap(dstbmp, 10, 10, null);
5. 位图旋转
同样,位图的旋转也可以借助Matrix或者Canvas来实现。
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pic180);Matrix matrix=new Matrix();matrix.postScale(0.8f, 0.8f);matrix.postRotate(45);Bitmap dstbmp=Bitmap.createBitmap(bmp,0,0,bmp.getWidth(),bmp.getHeight(),matrix,true);canvas.drawColor(Color.BLACK);canvas.drawBitmap(dstbmp, 10, 10, null);
旋转效果:

6.图片水印的生成方法
生成水印的过程。其实分为三个环节:第一,载入原始图片;第二,载入水印图片;第三,保存新的图片。
/**
* create thebitmapfrom a byte array
*
* @param src thebitmapobject you want proecss
* @param watermark the water mark above the src
* @return return abitmapobject ,if paramter's length is 0,return null
*/
privateBitmap createBitmap( Bitmap src, Bitmap watermark )
{
String tag ="createBitmap";
Log.d( tag,"create a newbitmap");
if( src ==null)
{
returnnull;
}
intw = src.getWidth();
inth = src.getHeight();
intww = watermark.getWidth();
intwh = watermark.getHeight();
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-21569-2.html
方便面是人家日本人发明的
这与买到有虫子的青菜一样