[英]android cordova-plugin-camera adds black background on PNG
经过测试:Android 4.2和Android 5.1.1
插件: https : //github.com/apache/cordova-plugin-camera
当我们从库中导入带有alpha(透明)层的PNG时,它将自动添加黑色背景。
您知道如何在插件返回的base64字符串中将黑色背景替换为白色背景吗?
使用的代码:
var options = {
quality: 95,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
allowEdit: true,
encodingType: Camera.EncodingType.PNG,
saveToPhotoAlbum: false
};
我找到了一种阅读Android位图的方法:将透明像素转换为颜色
然后应用于我们的代码,您必须更新CameraLauncher.java:
添加库进行编辑:
import android.graphics.Canvas;
import android.graphics.Color;
然后在第595行周围添加(如果您已添加了两个导入),此代码是从另一个线程获取并改编而成的:
Bitmap imageWithBG = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(),bitmap.getConfig()); // Create another image the same size
imageWithBG.eraseColor(Color.WHITE); // set its background to white, or whatever color you want
Canvas canvas = new Canvas(imageWithBG); // create a canvas to draw on the new image
canvas.drawBitmap(bitmap, 0f, 0f, null); // draw old image on the background
bitmap.recycle(); // clear out old image
bitmap = imageWithBG;
我提出了拉取请求,也许它将集成在下一个更新中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.