简体   繁体   English

有没有 Javascript function 可以反转相机的所有 colors(负面效果)?

[英]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.所以,我正在使用 Appcelerator Titanium (NOT ALLOY) 来构建一个应用程序(主要用于 Android),它可以打开相机并读取二维码。 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.但是,有些版本的 QRCode 已经反转了 colors,我的应用程序无法读取它们。 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.因此,我也在尝试找到一种方法来反转相机的视图,以便可以将 QRCode 读取为普通的 QRCode。

I have tried some functions to turn the colors hex code into RGB.我尝试了一些功能将 colors 十六进制代码转换为 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.我曾尝试使用 CSS 添加过滤器,但只能在 Alloy 中使用,而不是常见的 Ti.UI 项目,这是我的情况。

    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....

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:如果您使用的是 ZXing,我假设您是这样,并且如果您只想读取反转的代码颜色,请尝试在 DecodeHandler class 的decode()上添加此代码:

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.它不会将相机反转为负片,但它会像普通条形码/二维码一样工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM