gpt4 book ai didi

Android合并两张图片

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:45:56 24 4
gpt4 key购买 nike

我有这两张图片,基本上是在 Canvas 上合并的。现在我想将该 Canvas 保存到图像中。我应该怎么做,或者是否有任何其他方法可以合并两个图像。

我的示例代码是 -

            Bitmap bmp1 = BitmapFactory.decodeResource(getResources(),
R.drawable.duckpic);
Bitmap bmp2 = BitmapFactory.decodeResource(getResources(),
R.drawable.img);
// canvas.drawColor(Color.BLACK);
// canvas.drawBitmap(_scratch, 10, 10, null);
Bitmap bmOverlay = Bitmap.createBitmap(bmp2.getWidth(), bmp2
.getHeight(), bmp2.getConfig());
// Canvas cs = new Canvas(bmp2);
canvas.scale((float) 0.5, (float) 0.5);
canvas.drawBitmap(bmp2, new Matrix(), null);
canvas.drawBitmap(bmp1, new Matrix(), null);
canvas.save();

我通过这样做让它工作 -

    cs = Bitmap.createBitmap(c.getWidth(), c.getHeight(), Bitmap.Config.ARGB_8888);

Canvas comboImage = new Canvas(cs);

comboImage.drawBitmap(s, new Matrix(), null);
comboImage.drawBitmap(c, new Matrix(), null);
comboImage.save();
// this is an extra bit I added, just incase you want to save the new
// image somewhere and then return the location

String tmpImg = String.valueOf(System.currentTimeMillis()) + ".png";

OutputStream os = null;
try {
os = new FileOutputStream("/sdcard/" + tmpImg);
cs.compress(CompressFormat.PNG, 100, os);
} catch (IOException e) {
Log.e("combineImages", "problem combining images", e);
}

基本上这里给出了-http://www.jondev.net/articles/Combining_2_Images_in_Android_using_Canvas

最佳答案

使用canvas.setBitmap(Bitmap bitmap) .这会将 Canvas 发送到指定的位图。您需要为此创建一个新的可变位图。调用 setBitmap 后,您可以将该位图保存到文件中。

关于Android合并两张图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6129520/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com