我想旋转图像,这是我从memoryStream获得的。
我试过使用UIView:
private Stream TransformImageFromStream(MemoryStream stream, CGAffineTransform transform)
{
var bytes = stream.ToBytes ();
var data = NSData.FromArray (bytes);
var image = UIImage.LoadFromData (data);
var uiImage = new UIImageView (image);
uiImage.Transform = transform;
var result = uiImage.Image.AsPNG ().AsStream ();
var testBytes = result.ToBytes ();
if (testBytes [0] == bytes [0])
{
// throw new Exception ("test failed");
}
return result;
}
但是变换永远不会像在图形画布中一样使用UIView。
我发现某个地方可以将ApplyTransform直接用于CIImage
private Stream TransformImageFromStream(MemoryStream stream, CGAffineTransform transform)
{
var bytes = stream.ToBytes ();
using (var data = NSData.FromArray (bytes))
using (var ciImage = CIImage.FromData (data))
using (var transformedImage = ciImage.ImageByApplyingTransform (transform))
using (var uiImage = UIImage.FromImage(ciImage))
using (var uiImageView = new UIImageView(uiImage))
{
var result = uiImage.AsPNG ();
return null;
}
}
但UIImage不想将其转换为AsPng()以将其转换为流。在这种情况下,我注意到CGImage是空的,大多数属性设置为0.也许,有一些方法来转换CIImage本身,没有任何包装?
我没有更多关于该做什么的线索。