1

我有 2 个位图,一个是:宽度 720 x 404 高度。另一个是 1280x550 我用这个功能:

public Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
    Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
    Bitmap bmp2new = getResizedBitmap(bmp2, bmp1.getHeight(), bmp1.getWidth(), bmp2.getConfig());
    Canvas canvas = new Canvas(bmOverlay);
    canvas.drawBitmap(bmp1, new Matrix(), null);
    canvas.drawBitmap(bmp2new, 0, 0, null);
    return bmOverlay;
    }

现在它向我展示了两者。覆盖。现在第一个是视频的屏幕截图,第二个是我绘制的画布。问题是,如果我在屏幕边缘的东西上画一些东西,它将被错误地覆盖(偏移),因为我的视频被拉伸到与第二张图片相同。我能做些什么来放置两张图片,但屏幕截图以几个像素的偏移量开始,所以它会被正确放置?

我试过:

  int left = (int)((bmp2.getWidth() - (bmp1.getWidth()*(bmp2.getHeight()/bmp1.getHeight())))/2.0);
    Bitmap bmp1new = getResizedBitmap(bmp1, bmp2.getHeight(), ((bmp2.getWidth() - (bmp1.getWidth()*(bmp2.getHeight()/bmp1.getHeight())) , bmp1.getConfig());
  Bitmap bmptest = Bitmap.createBitmap(bmp1new, left, 0,bmp1new.getWidth() - left, bmp1new.getHeight());

但是没有运气,现在我更加困惑

4

1 回答 1

0

它适用于此:

   public Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
    Bitmap bmOverlay = Bitmap.createBitmap(bmp2.getWidth(), bmp2.getHeight(), bmp1.getConfig());
    float left =(bmp2.getWidth() - (bmp1.getWidth()*((float)bmp2.getHeight()/(float)bmp1.getHeight())))/(float)2.0;
    float bmp1newW = bmp1.getWidth()*((float)bmp2.getHeight()/(float)bmp1.getHeight());
    Bitmap bmp1new = getResizedBitmap(bmp1, bmp2.getHeight(), (int)bmp1newW , bmp1.getConfig());
    Canvas canvas = new Canvas(bmOverlay);
    canvas.drawBitmap(bmp1new, left ,0 , null);
    canvas.drawBitmap(bmp2, new Matrix(), null);
    return bmOverlay;
    }
于 2013-02-01T09:17:26.823 回答