繁体   English   中英

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

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

所以,我正在使用 Appcelerator Titanium (NOT ALLOY) 来构建一个应用程序(主要用于 Android),它可以打开相机并读取二维码。 到目前为止,一切都很好,它做了它应该做的事情。 但是,有些版本的 QRCode 已经反转了 colors,我的应用程序无法读取它们。 因此,我也在尝试找到一种方法来反转相机的视图,以便可以将 QRCode 读取为普通的 QRCode。

我尝试了一些功能将 colors 十六进制代码转换为 RGB。 例如,我将在下面发布代码的某些部分。

请,如果有人有解决方案,请帮助我! =)

我曾尝试使用 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....

如果您使用的是 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();
    }
  }

它不会将相机反转为负片,但它会像普通条形码/二维码一样工作。

暂无
暂无

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

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