android cordova-plugin-camera 在 PNG 上添加黑色背景
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 Bitmap: Convert transparent pixels to a color
然后应用于我们的代码你必须更新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;
我提出了一个拉取请求,也许它会在下一次更新中集成。
测试于: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 Bitmap: Convert transparent pixels to a color
然后应用于我们的代码你必须更新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;
我提出了一个拉取请求,也许它会在下一次更新中集成。