javascriptandroidtitaniumappcelerator-titaniumappcelerator-mobile

Is there a Javascript function to invert all the colors (negative effect) of the camera?


So, I am using Appcelerator Titanium (NOT ALLOY) to build an App (for Android mostly) that opens the camera and reads a QR Code. So far, so good, it does what it should be. But, there is some versions of QRCode that have inverted colors, and my App isn't able to read them. So, I am trying to find a way to invert the view of the camera as well, so the QRCode can be read as a normal QRCode.

I have tried some functions to turn the colors hex code into RGB. Bellow I will post some parts of the code for example.

Please, if anyone has a solution, help me! =)

I have tried to use CSS to add filters, but it is only possible in Alloy, not common Ti.UI projects, which is my case.

    var overlay = Ti.UI.createView({
    backgroundColor: 'transparent',
    top: 0,
    right: 0,
    bottom: 0,
    left: 0,
    id: 'overlay',
});
//the overlay is called when the camera opens, it is the main view in which I have to invert the colors....

function rgbaToHex(r, g, b, a) {
    var toHex = function(n) {
        return ('00' + (n | 0).toString(16)).slice(-2);
    };
    return '#' + toHex(((a * 100) / 100) * 255) + toHex(r) + toHex(g) + toHex (b);
};
//this is a rgba to hex function I found on the web, and it works, just not as I need it....

Solution

  • If you are using ZXing, which I assume you are, and if you just want to read the inverted code colours, try adding this on decode() at the DecodeHandler class:

    if (rawResult == null) {
        LuminanceSource invertedSource = source.invert();
        bitmap = new BinaryBitmap(new HybridBinarizer(invertedSource));
        try {
          rawResult = multiFormatReader.decodeWithState(bitmap);
        } catch (NotFoundException e) {
          // continue
        } finally {
          multiFormatReader.reset();
        }
      }
    

    It won't invert the camera to negative, but it will work just as it was a regular barcode/QRCode.