3

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.

Nadir Belhaj
  • 11,953
  • 2
  • 22
  • 21
r121
  • 274
  • 1
  • 6
  • Does your build of cordova support `encodingType`? – Jongware Sep 16 '14 at 21:07
  • +1 yes there are some issue with camera plugin another one is like http://stackoverflow.com/questions/25800878/file-name-is-changed-when-using-allowedit-in-phonegap/25803398#25803398 – Aravin Sep 17 '14 at 08:05

1 Answers1

0

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

r121
  • 274
  • 1
  • 6