小编Rob*_*bin的帖子

从 AVCapturePhotoOutput 裁剪 CGRect (resizeAspectFill)

我发现了以下问题,不幸的是其他帖子没有帮助我找到可行的解决方案。

我有一个简单的应用程序,显示相机预览 (AVCaptureVideoPreviewLayer),其中视频重力已设置为 resizeAspectFill ( videoGravity = .resizeAspectFill)。

根据我的理解,这只会拉伸图像的宽度以填充屏幕。

在我的预览图层上,我还应用了 CGRect 作为具有固定 x、y、宽度和高度的蒙版。

现在,一旦我拍照,我就会尝试从图像中裁剪出确切的矩形。根据我的理解,我应该使用某种数学将 CGRect 转换为与我从 AVCapturePhotoOutput 方法获得的图像相同的宽高比,但它似乎从未在宽度上正确裁剪。

    private func cropImage(image: UIImage) {
        let rect = CGRect(x: 25, y: 150, width: 325, height: 230)
        
        
        let scale = CGAffineTransform(scaleX: 1/self.view.frame.width, y: 1/self.view.frame.height)
        let flip = CGAffineTransform(scaleX: 1, y: -1).translatedBy(x: 0, y: -1)
        
        let bounds = rect.applying(scale).applying(flip)
        
        
        let topLeft = bounds.topLeft.scaled(to: image.size)
        let topRight = bounds.topRight.scaled(to: image.size)
        let bottomLeft = bounds.bottomLeft.scaled(to: image.size)
        let bottomRight = bounds.bottomRight.scaled(to: image.size)
        
        var ciImage = CIImage(image: …
Run Code Online (Sandbox Code Playgroud)

crop cgrect swift avcapturephotooutput

5
推荐指数
1
解决办法
609
查看次数

Flutter Blue 设置通知

我现在一直在使用 flutter Blue 一些,但我坚持以下几点:我正在使用我在https://github.com/pauldemarco/flutter_blue 上下载的示例应用程序,通过这里的基本想法是尽快当我连接到我的蓝牙设备时,它开始检查服务“FFE0”是否存在,然后是特征“FFE1”。这个特性会吐出我的项目需要的随机字符串。

具有特征打开的屏幕图像

通过屏幕,我可以看到上述情况是正确的,我只需要在它连接到蓝牙设备后立即以某种方式自动设置该特性的通知。

这是我正在 _Connect 函数中测试的一些当前代码。

_connect(BluetoothDevice d) async {
    device = d;
    // Connect to device
    deviceConnection = _flutterBlue
        .connect(device, timeout: const Duration(seconds: 4))
        .listen(
      null,
      onDone: _disconnect,
    );

// Update the connection state immediately
    device.state.then((s) {
      setState(() {
        deviceState = s;
      });
    });

// Subscribe to connection changes
    deviceStateSubscription = device.onStateChanged().listen((s) {
      setState(() {
        deviceState = s;
      });
      if (s == BluetoothDeviceState.connected) {
        device.discoverServices().then((service) {
          service.forEach((_service){
            var characteristics = _service.characteristics;
            _service.characteristics.map((c) { …
Run Code Online (Sandbox Code Playgroud)

android bluetooth ios dart flutter

3
推荐指数
1
解决办法
4340
查看次数

标签 统计

android ×1

avcapturephotooutput ×1

bluetooth ×1

cgrect ×1

crop ×1

dart ×1

flutter ×1

ios ×1

swift ×1