1个回答
展开全部
ImageView imageView = (ImageView)findViewById(R.id.imageview);
imageView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//当按下时获取到屏幕中的xy位置
if(event.getAction()==MotionEvent.ACTION_DOWN){
Log.e("point",event.getX() +","+event.getY());
//更多关于坐标转换的参考
Drawable drawable = imageView.getDrawable();
Rect imageBounds = drawable.getBounds();
//初始化bitmap的宽高
int intrinsicHeight = drawable.getIntrinsicHeight();
int intrinsicWidth = drawable.getIntrinsicWidth();
//可见image的宽高
int scaledHeight = imageBounds.height();
int scaledWidth = imageBounds.width();
//使用fitXY
float heightRatio = intrinsicHeight / scaledHeight;
float widthRatio = intrinsicWidth / scaledWidth;
//获取图像边界值
int scaledImageOffsetX = event.getX() - imageBounds.left;
int scaledImageOffsetY = event.getY() - imageBounds.top;
//根据你图像的缩放比例设置
int originalImageOffsetX = scaledImageOffsetX * widthRatio;
int originalImageOffsetY = scaledImageOffsetY * heightRatio;
imageView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//当按下时获取到屏幕中的xy位置
if(event.getAction()==MotionEvent.ACTION_DOWN){
Log.e("point",event.getX() +","+event.getY());
//更多关于坐标转换的参考
Drawable drawable = imageView.getDrawable();
Rect imageBounds = drawable.getBounds();
//初始化bitmap的宽高
int intrinsicHeight = drawable.getIntrinsicHeight();
int intrinsicWidth = drawable.getIntrinsicWidth();
//可见image的宽高
int scaledHeight = imageBounds.height();
int scaledWidth = imageBounds.width();
//使用fitXY
float heightRatio = intrinsicHeight / scaledHeight;
float widthRatio = intrinsicWidth / scaledWidth;
//获取图像边界值
int scaledImageOffsetX = event.getX() - imageBounds.left;
int scaledImageOffsetY = event.getY() - imageBounds.top;
//根据你图像的缩放比例设置
int originalImageOffsetX = scaledImageOffsetX * widthRatio;
int originalImageOffsetY = scaledImageOffsetY * heightRatio;
追问
谢谢你的回答,,我现在想在标注的地方插入图片,,这个怎么弄啊~
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询