English 中文(简体)
利用摄像机包改变摄像机在冲碎中的摄像机
原标题:change tint and saturation of live camera in flutter using camera package

change tint and saturation of live camera in flutter using camera package I have developed flutter app with camera package that preview live camera and record video or shoot photo and saves it. I want to change color and saturation of preview and apply it to video and camera. how can I achieve that/.

没有发现任何变化的int和饱和情况

问题回答

除非你想重订摄影机的部件,否则这必须是一个两步过程。 您might 能够从照相机中取出并直接处理,但我的猜测是,在不出现重大业绩问题的情况下,不可能这样做。

Instead, the first step is going to be to change the preview in real-time to show hue + saturation changes. To do this, you can use ColorFilter widgets which wrap the preview widget. You re going to need to set these ColorFilters to perform the manipulation you d like; I d recommend looking at the Color Filter Generator pub package which includes the math for a bunch of different matrices including hue, saturation, brightness.

这里的一个例子是,你可以 past到dartpad.dev,看看它所看的情况。 但是,这个理论家是,使用<代码>hueMatrix和生成我随后转至图像Filter物体的矩阵方法的Im。 如果你想要的话,你甚至可以把使ShueMatrix和饱和Matrix功能合并为一种功能,但我可以让你完成这项工作。 比如,Im将过滤器应用到文字上,但对于照相机的预约来说,它应当做到同样。

import  package:flutter/material.dart ;
import  dart:math ;

// from https://github.com/hsbijarniya/colorfilter_generator
List<double> hueMatrix(double value) {
  value = value * pi;

  if (value == 0) {
    return [
      1,
      0,
      0,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      0,
      0,
      1,
      0,
    ];
  }

  var cosVal = cos(value);
  var sinVal = sin(value);
  var lumR = 0.213;
  var lumG = 0.715;
  var lumB = 0.072;

  return List<double>.from(<double>[
    (lumR + (cosVal * (1 - lumR))) + (sinVal * (-lumR)),
    (lumG + (cosVal * (-lumG))) + (sinVal * (-lumG)),
    (lumB + (cosVal * (-lumB))) + (sinVal * (1 - lumB)),
    0,
    0,
    (lumR + (cosVal * (-lumR))) + (sinVal * 0.143),
    (lumG + (cosVal * (1 - lumG))) + (sinVal * 0.14),
    (lumB + (cosVal * (-lumB))) + (sinVal * (-0.283)),
    0,
    0,
    (lumR + (cosVal * (-lumR))) + (sinVal * (-(1 - lumR))),
    (lumG + (cosVal * (-lumG))) + (sinVal * lumG),
    (lumB + (cosVal * (1 - lumB))) + (sinVal * lumB),
    0,
    0,
    0,
    0,
    0,
    1,
    0,
  ]).map((i) => i.toDouble()).toList();
}

// from https://github.com/hsbijarniya/colorfilter_generator
List<double> saturationMatrix(double value) {
  value = value * 100;

  if (value == 0) {
    return [
      1,
      0,
      0,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      0,
      0,
      1,
      0,
      0,
      0,
      0,
      0,
      1,
      0,
    ];
  }

  var x =
      ((1 + ((value > 0) ? ((3 * value) / 100) : (value / 100)))).toDouble();
  var lumR = 0.3086;
  var lumG = 0.6094;
  var lumB = 0.082;

  return List<double>.from(<double>[
    (lumR * (1 - x)) + x,
    lumG * (1 - x),
    lumB * (1 - x),
    0,
    0,
    lumR * (1 - x),
    (lumG * (1 - x)) + x,
    lumB * (1 - x),
    0,
    0,
    lumR * (1 - x),
    lumG * (1 - x),
    (lumB * (1 - x)) + x,
    0,
    0,
    0,
    0,
    0,
    1,
    0,
  ]).map((i) => i.toDouble()).toList();
}

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  double hue = 0;
  double saturation = 0;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            MyWidget(hue: hue, saturation: saturation),
            Text("Hue:"),
            Slider(
              value: hue / 2 + .5,
              onChanged: (val) => setState(() => hue = val * 2 - 1),
            ),
            Text("Saturation:"),
            Slider(
              value: saturation / 2 + .5,
              onChanged: (val) => setState(() => saturation = val * 2 - 1),
            )
          ],
        ),
      ),
    );
  }
}

class MyWidget extends StatelessWidget {
  final double hue;
  final double saturation;

  const MyWidget({super.key, required this.hue, required this.saturation});

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    return ColorFiltered(
      colorFilter: ColorFilter.matrix(hueMatrix(hue)),
      child: ColorFiltered(
        colorFilter: ColorFilter.matrix(
          saturationMatrix(saturation),
        ),
        child: Text(
           Hello, World! ,
          style: theme.textTheme.headlineMedium!
              .copyWith(color: theme.primaryColor),
        ),
      ),
    );
  }
}

这是你问题的第一个部分;现在,你们有一个预告,显示有饱和、hu的录像,或者任何其他应用。


The second part is going to be a lot more dependent on a bunch of other factors such as which format you re recording, what you re doing with the video etc. But basically, once you call stopVideoRecording on the camera, you ll be given a XFile object which contains the data from the video. Should be similar for if you re taking a picture.

您也许能够利用一个原始资料,例如tapioca<>, 供当时使用的录像,以添加正确的字塔,但我觉得自己没有足够功能。 如果是这样,你很可能需要包括约3个特定方和甲状腺素(如果你重新使用这种物质的话,是SOS)包,然后从冲碎打到洗 actual实际的胡 &;饱和任何其它东西,然后等待处理,然后就与档案做任何其它事情。

对于图像而言,除了可能更容易获得的原始材料外,你还拥有类似的过程,而且如果你能够照相操作——>:编辑可能做成像,因为它似乎支持采用一种彩色矩阵。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签