how can we compress an IMAGE file from camera and store it store it in our DB.
To Compress an image file, which is been taken by Native Camera, following attribute is been used :

quality : It compresses the image and reduces the size of the image.Its value ranges from 1-100, where 100 means best quality image.


Code: Select all

var jsonobj = {
        targetWidth: "200", 
        targetHeight: "200",
        crop: "Y",
        flash: "N",
        action: "base64_Save",
        fileName: imageNumber.toString(),
        quality: "50",
        encodingType: "JPG",
        sourceType: "Camera",
        openNativeCamera: "Y",
        fileOverwrite: "N"
To Insert Compressed Image in DB, we are supposed to use SQL Storage plugin of Appzillon

The storage plugin helps to do the following in the SQLite database available on the mobile device:

• Create a database
• Create tables in the database created
• Insert data into the tables in the database
• Select data from database
• Delete data from database.

How can we convert an encoded IMAGE base 64 to IMAGE.
To get base64 encode image from Appzillon's camera plugin, please pass action as base64, after image is been taken, it will return encoded base 64 string in encodedImage in success call back , and that base 64 can displayed in HTML Image using src

Example :

To launch camera and get base64 string in success call back :

Code: Select all

var jsonobj = {
"zoomLevel": "20", 
"targetWidth": "200",
"crop": "Y",//Y or N 
"flash": "N",
"action": "base64", 
"fileName": “Sample”,
"quality" : "50",
"encodingType" : "JPG",
"sourceType":"camera"   // photo
}; = "CAMERA_ID";
    	jsonobj.callBack = cameraCallback;
To Display Image in HTML, in success callback :

Code: Select all

cameraCallback = function(pjson){
document.getElementById("loadImage").src = "data:image/jpg;base64," + pjson.encodedImage;
In the same manner, if are retrieving image base 64 from database we can display it in HTML.