简体   繁体   English

在缩放或拖动(左,右,上,下)图像时,如何设置另一个视图的精确位置?

[英]How to set exactly position another view when zoom or drag (left, right, up, down) image?

I met a big trouble in this case. 在这种情况下,我遇到了很大的麻烦。 I have a imageview (green icon) added on Image background. 我在图像背景上添加了一个imageview(绿色图标)。 Green icon's position is set dynamically(Pic 1) 绿色图标的位置是动态设置的(图片1)

在此处输入图片说明

This Image can zoom in, zoom out, drag left, right, up, down. 该图像可以放大,缩小,向左,向右,向上,向下拖动。 I want to to move exactly imageview's position (green icon) when zoom or drag image background. 缩放或拖动图像背景时,我想精确移动imageview的位置(绿色图标)。

How can I map imageview's position (green icon) with Image background when I zoom, drag Image background? 缩放,拖动图像背景时,如何用图像背景映射imageview的位置(绿色图标)?

Picture 2: Image background is zoomed but green icon view does not map with image background, it's wrong position. 图片2:图像背景已放大,但绿色图标视图未与图像背景对应,这是错误的位置。

在此处输入图片说明

Can you suggest me some solution, direction or scripts. 您能建议我一些解决方案,方向或脚本吗? Thanks all! 谢谢大家!

use following function which will overlay your image bitmap with mark image bitmap and return new bitmap which you can use to display 使用以下功能,该功能将用标记图像位图覆盖您的图像位图并返回可用于显示的新位图

private Bitmap overlay(Bitmap bmp1, Bitmap bmp2, float left, float top) {
        Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
        Canvas canvas = new Canvas(bmOverlay);
        canvas.drawBitmap(bmp1, new Matrix(), null);
        canvas.drawBitmap(bmp2, left, top, null); 
        return bmOverlay;
    }

eg :- 例如:-

        Bitmap border = null;
        Bitmap scaledBorder = null;
        border = BitmapFactory.decodeResource(getResources(), R.drawable.palette);
        scaledBorder = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        ImageView im = (ImageView) findViewById(R.id.imageView);
        im.setImageBitmap(overlay(border, scaledBorder, 0, 0));// replace both 0,0 point with your mark point 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Android 上左右拖动 imageview 上下左右? - how to drag imageview left,right,up,and down on Android? 如何在基本四个方向(即右,左,上,下)上滑动视图中的图像 - how to swipe an image in a view in basic four directions i.e. right, left, up, down 如何根据玩家的需要上,下,左或右移动图像? - how to move an image up, down, left or right as the player wants? 如何检测向左,向右,向上和向下的移动 - How to detect movement to the left, right, up and down 如何在不使用android模拟器(pdf查看器)上下滚动的情况下从左至右读取pdf文件? - How to read a pdf file from left to right position without scrolling up & down in android emulator(pdf viewer)? 将视图与另一个视图的左右位置对齐,约束布局? - Align view to left and right position of another view, constraint layout? 当我在其上应用捏缩放时,如何在中心设置图像视图? - how to set image view in center when i apply pinch zoom on it? 当我单击按钮时如何设置动画,在android中从左向右和从右向左移动图像? - How to set animation when I click on button at that time move image from left to right and right to left in android? 拖动捏缩放时获取缩放图像视图的最后一点 - Get the last point of zoomed image view when drag in pinch zoom 如何在Android中向右,向左,向上和向下移动缩放图像? - How to move right, left,top and bottom for zoom Image in android?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM