繁体   English   中英

Android在画布中指定的X,Y位置绘制位图

[英]Android draw the bitmap in specified X,Y positions in the canvas

我有两个图像,第一个图像具有透明区域。第二个图像必须适合第一个图像的透明区域。 为此,我具有第一个图像的高度,宽度,x,y值。我通过在画布上绘制位图来组合这两个图像,如下所示。

Bitmap bm = Bitmap.createBitmap(overLay.getWidth(),
            overLay.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas combineImg = new Canvas(bm);

    combineImg.drawBitmap(overLay, 0, 0, null);
    // combineImg.drawbitma
    combineImg.drawBitmap(mask, 61, 111, null);
    ImageView img = (ImageView) findViewById(R.id.image);
    img.setImageBitmap(bm);

但是它不适合正确的位置。 任何人都有想法请在这里解释。 我把得到的输出如下。 在此处输入图片说明

您将从顶部边缘获得xy位置...
当您合并它们时,会出现错误...
在图像视图中获取位图xy,减去误差,然后指定这些xy位置以合并位图。

    int ih = backgroundIv.getHeight();//height of imageView
    int iw = backgroundIv.getWidth();//width of imageView
    int iH = backgroundIv.getDrawable().getIntrinsicHeight();//original height of underlying image
    int iW = backgroundIv.getDrawable().getIntrinsicWidth();//original width of underlying image


    if (ih/iH<=iw/iW) iw=iW*ih/iH;//rescaled width of image within ImageView
    else ih= iH*iw/iW;//rescaled height of image within ImageView

    iv_OverlayImage.requestLayout();
    iv_OverlayImage.getLayoutParams().height = ih;
    iv_OverlayImage.getLayoutParams().width = iw;

    pixelsToRight = (backgroundIv.getWidth() - iw)/2;

我希望这会有所帮助...干杯:)

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM