You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.4 KiB
43 lines
1.4 KiB
using CameraPreview;
|
|
using CameraPreview.iOS;
|
|
using CoreGraphics;
|
|
using CoreVideo;
|
|
using System.IO;
|
|
using UIKit;
|
|
|
|
namespace Demo.iOS
|
|
{
|
|
public class IosDecoder : DefaultDecoderBase
|
|
{
|
|
private readonly FaceDecoder _faceDecoder = new FaceDecoder();
|
|
|
|
public override IScanResult Decode(CVPixelBuffer pixelBuffer)
|
|
{
|
|
pixelBuffer.Lock(CVPixelBufferLock.None);
|
|
var flags = CGBitmapFlags.PremultipliedFirst | CGBitmapFlags.ByteOrder32Little;
|
|
using (var cs = CGColorSpace.CreateDeviceRGB())
|
|
{
|
|
using (var context = new CGBitmapContext(pixelBuffer.BaseAddress,
|
|
pixelBuffer.Width,
|
|
pixelBuffer.Height,
|
|
8,
|
|
pixelBuffer.BytesPerRow,
|
|
cs,
|
|
(CGImageAlphaInfo)flags))
|
|
{
|
|
using (var cgImage = context.ToImage())
|
|
{
|
|
pixelBuffer.Unlock(CVPixelBufferLock.None);
|
|
var uiImage = UIImage.FromImage(cgImage);
|
|
using (var stream = new MemoryStream())
|
|
{
|
|
uiImage.AsJPEG().AsStream().CopyTo(stream);
|
|
this._faceDecoder.Decode(stream.ToArray());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return base.Decode(pixelBuffer);
|
|
}
|
|
}
|
|
} |