2015-07-12 24 views
2

在测试了:机器人4.2 &的Android 5.1.1机器人科尔多瓦-插件相机添加黑backgound上PNG

插件:https://github.com/apache/cordova-plugin-camera

当我们导入PNG与α(透明)从库层它自动添加黑色背景。

你知道如何将黑色背景替换为由插件返回的base64字符串中的白色背景吗?

代码使用:

var options = { 
         quality: 95, 
         destinationType: Camera.DestinationType.DATA_URL, 
         sourceType: Camera.PictureSourceType.PHOTOLIBRARY, 
         allowEdit: true, 
         encodingType: Camera.EncodingType.PNG, 
         saveToPhotoAlbum: false 
        }; 

回答

0

我发现了一个办法做到这一点读书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; 

我做了一个拉请求,也许将被集成在接下来的更新。

相关问题