我正在使用函數來將兩個位圖文件彼此對齊並且它也覆蓋。 我正在使用此函數將它覆蓋在一個另一個上。覆蓋位圖功能無法正常工作
public static Bitmap combineImages(Bitmap cameraImage, Bitmap visionImage) { // can add a 3rd parameter 'String loc' if you want to save the new image - left some code to do that at the bottom
Bitmap finalImage = null;
int width, height = 0;
width = cameraImage.getWidth();
height = cameraImage.getHeight();
finalImage = Bitmap.createBitmap(width, height, cameraImage.getConfig());
Canvas canvas = new Canvas(finalImage);
canvas.drawBitmap(cameraImage, new Matrix(), null);
canvas.drawBitmap(visionImage, new Matrix(), null);
// 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(loc + tmpImg);
finalImage.compress(CompressFormat.PNG, 100, os);
} catch(IOException e) {
Log.e("combineImages", "problem combining images", e);
}*/
return finalImage;
}
但保存完這個圖像後,我顯示圖像要相互結合。它不是覆蓋。我希望它可以疊加在一起。
請告訴我我在哪裏錯了這個函數? 謝謝。
你想結合位圖的像一個覆蓋另一個。 –
我的第一張圖片是cameraPicture和TransperentLayer的第二張圖片。所以我想把第二張傳送圖像疊加到FirstOne圖像上。 –
看到我的答案,它會做.. –