【问题标题】:Android draw the bitmap in specified X,Y positions in the canvasAndroid在画布中指定X,Y位置绘制位图
【发布时间】:2014-10-02 16:19:03
【问题描述】:

我有两张图片,第一张图片是透明区域 那。第二张图片我必须适合第一张的透明区域 图片 。为此,我有第一个图像高度、宽度、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);

但它不适合正确的位置。任何人有想法请在这里解释。 我得到的输出如下。

【问题讨论】:

  • @pskink 这些是服务器发送的 x,y 坐标。与 ios 中的那些 x,y 值匹配在正确的位置

标签: android bitmap android-canvas


【解决方案1】:

您正在从顶部边缘获取 x y 位置...
当您合并它们时,就会出现错误...
在图像视图中获取位图 x y,减去误差,然后给出这些 x y 位置以合并位图。

    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;

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

【讨论】:

    猜你喜欢
    • 2012-11-30
    • 2012-11-01
    • 2022-09-30
    • 2014-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-06
    相关资源
    最近更新 更多