Android中几种图像特效处理的集锦(2)

第三步:修改main.xml布局文件,主要放了两个ImageView控件,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
 <ImageView
  android:id="@+id/image01"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:padding="10px"
     />
 <ImageView
  android:id="@+id/image02"
  android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:padding="10px"
 />
</LinearLayout>

第四步:修改主核心程序,ImageDemo.java,代码如下:

package com.android.tutor;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;
public class Imagedemo extends Activity {
 private ImageView mImageView01,mImageView02;
 
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setupViews();
    }
  
    private void setupViews(){
     mImageView01 = (ImageView)findViewById(R.id.image01);
     mImageView02 = (ImageView)findViewById(R.id.image02);
     
     //获取壁纸返回值是Drawable
     Drawable drawable = getWallpaper();
     //将Drawable转化为Bitmap
     Bitmap bitmap = ImageUtil.drawableToBitmap(drawable);
     //缩放图片
     Bitmap zoomBitmap = ImageUtil.zoomBitmap(bitmap, 100, 100);
     //获取圆角图片
     Bitmap roundBitmap = ImageUtil.getRoundedCornerBitmap(zoomBitmap, 10.0f);
     //获取倒影图片
     Bitmap reflectBitmap = ImageUtil.createReflectionImageWithOrigin(zoomBitmap);
     //这里可以让Bitmap再转化为Drawable
//     Drawable roundDrawable = new BitmapDrawable(roundBitmap);     
//     Drawable reflectDrawable = new BitmapDrawable(reflectBitmap);    
//     mImageView01.setBackgroundDrawable(roundDrawable);
//     mImageView02.setBackgroundDrawable(reflectDrawable);
          
     mImageView01.setImageBitmap(roundBitmap);
     mImageView02.setImageBitmap(reflectBitmap);
    }
     
      
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwsfxp.html