本文整理匯總了Java中android.graphics.Canvas.setDrawFilter方法的典型用法代碼示例。如果您正苦於以下問題:Java Canvas.setDrawFilter方法的具體用法?Java Canvas.setDrawFilter怎麽用?Java Canvas.setDrawFilter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.Canvas
的用法示例。
在下文中一共展示了Canvas.setDrawFilter方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dispatchDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void dispatchDraw(Canvas canvas) {
super.dispatchDraw(canvas);
if (mChanged && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
post(new Runnable() {
@Override
public void run() {
if (mAttached && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
final int layerType = getLayerType();
// If it's already a hardware layer, it'll be built anyway.
if (layerType != LAYER_TYPE_HARDWARE || mFirst) {
mFirst = false;
setLayerType(LAYER_TYPE_HARDWARE, null);
buildLayer();
setLayerType(LAYER_TYPE_NONE, null);
}
}
}
});
mChanged = false;
}
PaintFlagsDrawFilter pfd = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint
.FILTER_BITMAP_FLAG);
canvas.setDrawFilter(pfd);
}
示例2: getRoundedCornerBitmap
import android.graphics.Canvas; //導入方法依賴的package包/類
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
paint.setDither(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
示例3: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
public void onDraw(Canvas canvas) {
canvas.setDrawFilter(new PaintFlagsDrawFilter(0, 3));
int W = canvas.getWidth();
int H = canvas.getHeight();
Rect frame = CameraManager.get().getFramingRect();
if (frame != null) {
drawCover(canvas, frame, W, H);
if (this.resultBitmap != null) {
canvas.drawBitmap(this.resultBitmap, (float) frame.left, (float) frame.top, this.paint);
return;
}
drawScanningLine(canvas, frame);
drawRectEdge(canvas, frame);
this.paint.reset();
postInvalidateDelayed(ANIMATION_DELAY);
}
}
示例4: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.setDrawFilter(new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG));
if (mAnimator_visible.isRunning()) {
int x = (int) mAnimator_visible.getAnimatedValue();
drawClear(x, canvas);
invalidate();
} else if (isVisible) {
drawClear(0, canvas);
}
if (mAnimator_gone.isRunning()) {
float scale = (float) mAnimator_gone.getAnimatedValue();
drawClearGone(scale, canvas);
invalidate();
}
}
示例5: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
//從canvas層麵去除繪製時的鋸齒
canvas.setDrawFilter(mDrawFilter);
for(int i=0,j=0,k=0;i<mTotalWidth;i++){
if(i+mXOneOffset<mTotalWidth){//第一條波紋圖形繪製
canvas.drawLine(i,mTotalHeight-mYPositions[mXOneOffset+i]-WaveHeight,i,mTotalHeight,mWavePaint);
}else {//大於周期值,則設置為j(與相位相關,已移動的X距離,最大值為一個周期,即控件的寬度)
canvas.drawLine(i,mTotalHeight-mYPositions[j]-WaveHeight,i,mTotalHeight,mWavePaint);
j++;
}
if(i+mXTwoOffset<mTotalWidth){//第二條波紋圖形繪製
canvas.drawLine(i,mTotalHeight-mYPositions[mXTwoOffset+i]-WaveHeight,i,mTotalHeight,mWavePaint1);
}else {//大於周期值,則設置為k(與相位相關,已移動的X距離)
canvas.drawLine(i,mTotalHeight-WaveHeight-mYPositions[k],i,mTotalHeight,mWavePaint1);
k++;
}
}
// 改變兩條波紋的移動點
mXOneOffset += mXOffsetSpeedOne;
mXTwoOffset += mXOffsetSpeedTwo;
// 如果已經移動到結尾處,則重頭記錄
if (mXOneOffset >= mTotalWidth) {
mXOneOffset = 0;
}
if (mXTwoOffset > mTotalWidth) {
mXTwoOffset = 0;
}
// 引發view重繪,可以考慮延遲10-30ms重繪,空出時間繪製
if (isAnim){
new Thread(mRunnable).start();
}
}
示例6: dispatchDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void dispatchDraw(@NonNull Canvas canvas) {
PaintFlagsDrawFilter pfd = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint
.FILTER_BITMAP_FLAG);
canvas.setDrawFilter(pfd);
final int count = getChildCount();
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child == null)
return;
}
super.dispatchDraw(canvas);
}
示例7: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
mPath.reset();
mPath.addRoundRect(mRectF, rids, Path.Direction.CW);
canvas.setDrawFilter(paintFlagsDrawFilter);
canvas.save();
canvas.clipPath(mPath);
super.onDraw(canvas);
canvas.restore();
}
示例8: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.setDrawFilter(this.pfdf);
drawBg(canvas);
drawRuler(canvas);
drawIndicator(canvas);
}
示例9: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
canvas.setDrawFilter(pfd);
if (currentPoint == null) {
currentPoint = new Point(width, height);
drawShade(canvas);
startShadeAnimation();
} else {
drawShade(canvas);
}
}
示例10: onDraw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
canvas.setDrawFilter(mDrawFilter);
super.onDraw(canvas);
drawLines(canvas);
}
示例11: draw
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public void draw(Canvas canvas) {
canvas.setDrawFilter(pfd);
canvas.drawCircle(getWidth() / 2, getHeight() / 2, Math.max(getWidth(), getHeight()) / 2, mBgPaint);
super.draw(canvas);
}
示例12: getView
import android.graphics.Canvas; //導入方法依賴的package包/類
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ApplicationInfo info = mApplications.get(position);
if (convertView == null) {
final LayoutInflater inflater = getLayoutInflater();
convertView = inflater.inflate(R.layout.application, parent, false);
}
Drawable icon = info.icon;
if (!info.filtered) {
//final Resources resources = getContext().getResources();
int width = 42;//(int) resources.getDimension(android.R.dimen.app_icon_size);
int height = 42;//(int) resources.getDimension(android.R.dimen.app_icon_size);
final int iconWidth = icon.getIntrinsicWidth();
final int iconHeight = icon.getIntrinsicHeight();
if (icon instanceof PaintDrawable) {
PaintDrawable painter = (PaintDrawable) icon;
painter.setIntrinsicWidth(width);
painter.setIntrinsicHeight(height);
}
if (width > 0 && height > 0 && (width < iconWidth || height < iconHeight)) {
final float ratio = (float) iconWidth / iconHeight;
if (iconWidth > iconHeight) {
height = (int) (width / ratio);
} else if (iconHeight > iconWidth) {
width = (int) (height * ratio);
}
final Bitmap.Config c =
icon.getOpacity() != PixelFormat.OPAQUE ?
Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
final Bitmap thumb = Bitmap.createBitmap(width, height, c);
final Canvas canvas = new Canvas(thumb);
canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.DITHER_FLAG, 0));
// Copy the old bounds to restore them later
// If we were to do oldBounds = icon.getBounds(),
// the call to setBounds() that follows would
// change the same instance and we would lose the
// old bounds
mOldBounds.set(icon.getBounds());
icon.setBounds(0, 0, width, height);
icon.draw(canvas);
icon.setBounds(mOldBounds);
icon = info.icon = new BitmapDrawable(thumb);
info.filtered = true;
}
}
final TextView textView = (TextView) convertView.findViewById(R.id.label);
textView.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
textView.setText(info.title);
return convertView;
}