Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> Android開發 >> 初級開發 >> android 圓角圖片和灰度設置

android 圓角圖片和灰度設置

編輯:初級開發

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Bitmap.Config;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.ImageVIEw;
import android.widget.TextVIEw;public class ProfileActivity extends BaseActivity {
private static final String TAG = ProfileActivity.class.getName();
private static final int AVATAR_WHIDTH = 250;
private static final int AVATAR_HIGHT = 180;
final float roundPx = 12;private ImageVIEw people_avatar;
private ImageVIEw people_star;
private TextVIEw people_name;
private TextVIEw people_listeners;
private TextVIEw people_similar;
private TextVIEw people_tweer;
private Button   people_button;private Bitmap people_user_avatar_bitmap;
private Drawable people_user_avatar;
private Drawable star_strut_on;
private Drawable star_strut_off;// ----------------------------test data------------------
private int temp_many_int = 231;@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v(TAG, "onCreate ....");
setContentView(R.layout.people_profile);initVIEw(false);}/***
* 加載布局元素 isOnline 是否在線如果在線就原圖,否則灰度調整
*/
private void initVIEw(boolean isOnline) {
people_avatar     = (ImageView) findVIEwById(R.id.profile_avatar);
people_name     = (TextView) findVIEwById(R.id.profile_name);
people_listeners = (TextView) findVIEwById(R.id.profile_listeners);
people_similar   = (TextView) findVIEwById(R.id.profile_similar);
people_tweer     = (TextView) findVIEwById(R.id.profile_tweers);
people_star     = (ImageView)findVIEwById(R.id.prifile_star);
people_button    = (Button)findVIEwById(R.id.profile_button);
people_button.setText(getString(R.string.people_play));
// -----------------------補充模擬數據---------------------
people_name.setText("kiki");
people_listeners.setText(getString(R.string.people_many_listenters, new String[] { temp_many_int + "" }));
people_similar.setText(this.getString(R.string.people_similar));
people_tweer.setText(getString(R.string.people_tweers));
people_user_avatar = this.getResources().getDrawable(R.drawable.xyx);
people_star.setImageResource(R.drawable.btn_star_big_buttonless_on);
people_user_avatar_bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.background);
Bitmap output = Bitmap.createBitmap(AVATAR_WHIDTH, AVATAR_HIGHT, Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, AVATAR_WHIDTH, AVATAR_HIGHT);
final RectF rectF = new RectF(0, 0, AVATAR_WHIDTH, AVATAR_HIGHT);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setDither(true); // 獲取跟清晰的圖像采樣if (!isOnline) {   //灰度調整
people_button.setText(getString(R.string.people_follow));
ColorMatrix cm = new ColorMatrix();
cm.setSaturation(0);
ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
paint.setColorFilter(f);
people_star.setImageResource(R.drawable.btn_star_big_buttonless_off);
}
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(people_user_avatar_bitmap, rect, rect, paint);
people_avatar.setImageBitmap(output);}@Override
protected void onDestroy() {
super.onDestroy();
Log.v(TAG, "onDestroy ....");
}@Override
protected void onPause() {
super.onPause();
Log.v(TAG, "onPause ....");
}@Override
protected void onRestart() {
super.onRestart();
Log.v(TAG, "onRestart ....");
}@Override
protected void onResume() {
super.onResume();
Log.v(TAG, "onResume ....");
}@Override
protected void onStart() {
super.onStart();
Log.v(TAG, "onStart ....");
}@Override
protected void onStop() {
super.onStop();
Log.v(TAG, "onStop ....");
}}
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved