【Java开源代码栏目提醒】:网学会员Java开源代码为您提供MyImageView.java参考,解决您在MyImageView.java学习中工作中的难题,参考学习。
package org.chapter15;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.widget.ImageView;
public class MyImageView extends ImageView {
Paint mPaint = new Paint();
public static Path mPath = new Path();
public static boolean bClear = false;
private Bitmap mBitmap = Bitmap.createBitmap(320, 392, Bitmap.Config.ARGB_8888);
public static float mX, mY;
public static final float TOUCH_TOLERANCE = 4;
public static boolean bDrawWell = false;
public MyImageView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MyImageView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public MyImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
if(bClear) {
mPaint.setStyle(Paint.Style.FILL);
mPaint.setColor(Color.BLACK);
mBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
canvas.drawBitmap(mBitmap, 0, 0, mPaint);
bClear = false;
}
// draw rotatedBMP
canvas.drawBitmap(GestureOnImageV5.rotatedBMP, 0, 0, mPaint);
if(bDrawWell) {
// for drawing well-shape
int width = getWidth();
int height = getHeight();
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(Color.WHITE); // white
mPaint.setStrokeWidth(1);
// horizon
canvas.drawLine(0, height/3, width-1, height/3, mPaint);
canvas.drawLine(0, 2*height/3, width-1, 2*height/3, mPaint);
// vertical
canvas.drawLine(width/3, 0, width/3, height-1, mPaint);
canvas.drawLine(2*width/3, 0, 2*width/3, height-1, mPaint);
// end drawing well-shape
}
if(!bClear) {
mPaint.setStrokeJoin(Paint.Join.ROUND);
mPaint.setStrokeCap(Paint.Cap.ROUND);
mPaint.setStrokeWidth(6);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(Color.GREEN);
canvas.drawBitmap(mBitmap, 0, 0, mPaint);
canvas.drawPath (mPath, mPaint);
}
}
}
上一篇:
MyImageDialog.java
下一篇:
澳大利亚留学生英语会计案例分析报告:Blue Moon case study