How to get png pictures with Cordova 3.5 on Android

974 views Asked by At

I'm trying to retrieve a PNG picture using cordova-plugin-camera, with that code :

navigator.camera.getPicture(onPictSuccess, onFailPict, { quality: 50, encodingType:Camera.EncodingType.PNG, destinationType:navigator.camera.DestinationType.FILE_URI});

But it's always return a JPG file. Did someone succeed getting PNG on Android ?

Looking at tha java plugin source for Android in CameraLauncher.java l.390 and in many other locations ".jpg" seems to be hardcoded :

uri = Uri.fromFile(new File(getTempDirectoryPath(), System.currentTimeMillis() + ".jpg"));

I tried replacing ".jpg" with ".png" but of course that only change the name of the extension.

1

There are 1 answers

0
r121 On

Well, I was not so far from the solution. A few lines below in processResultFromCamera() (l.413) a jpeg reference is also hardcoded

bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);

that I replaced by :

if (this.encodingType == JPEG) {
    bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
}
else if (this.encodingType == PNG) {
     bitmap.compress(Bitmap.CompressFormat.PNG, this.mQuality, os);
}

So the plugin's doc is wrong PNG isn't supported for Android. And I don't know more about github to correct the code