C# 旋转可写位图而不创建新位图
好的,下面是它的工作原理: 摄像头将图像作为可写位图发送给我 client.WhenMasterFrameCaptured.ObserveOnSynchronizationContext.Current.Subscribeframe=>UpdateMasterCameraPreviewframe 我在订阅的方法中设置指向image sourcewpf image控件的指针C# 旋转可写位图而不创建新位图,c#,wpf,bitmap,C#,Wpf,Bitmap,好的,下面是它的工作原理: 摄像头将图像作为可写位图发送给我 client.WhenMasterFrameCaptured.ObserveOnSynchronizationContext.Current.Subscribeframe=>UpdateMasterCameraPreviewframe 我在订阅的方法中设置指向image sourcewpf image控件的指针 if (cameraOneBitmap != null) { fra
if (cameraOneBitmap != null)
{
frame.Image.CopyTo(cameraOneBitmap);
}
else
{
cameraOneBitmap = frame.Image.ToWriteableBitmap();
}
cameraOneBitmap.Lock();
cameraOneBitmap.AddDirtyRect(new Int32Rect(0, 0, cameraOneBitmap.PixelWidth, cameraOneBitmap.PixelHeight));
cameraOneBitmap.Unlock();
cameraOneImage.Source = cameraOneBitmap;
问题是:这个方法给了我一个角度不正确的位图,我没有办法改变它。我必须旋转它。我目前正在使用xaml中的渲染变换。问题是,在特定的窗口大小下,图像的形状都很奇怪,它挂在网格上,进入窗口底部,所以我不想使用它。我曾尝试使用writeablebitmapex库,但它创建了一个新位图,并在大约10秒内出现内存不足异常。。。是否有一种方法可以旋转此位图而不必每次都创建一个新位图?不知何故,渲染变换可以做到这一点,而不会给我带来问题。我这样做是为了设置源代码,但它仍然给了我一个异常,因为它生成了一个新的
public static RenderTargetBitmap RotateImage(double angle, WriteableBitmap sourceBitmap)
{
TransformedBitmap tb = new TransformedBitmap(sourceBitmap, new RotateTransform(angle));
DrawingVisual drawingVisual = new DrawingVisual();
DrawingContext drawingContext = drawingVisual.RenderOpen();
drawingContext.DrawImage(tb, new Rect(0, 0, tb.PixelWidth, tb.PixelHeight));
//drawingContext.PushTransform(new RotateTransform(270, .5, .5));
drawingContext.Close();
System.Windows.Media.Imaging.RenderTargetBitmap bmp = new System.Windows.Media.Imaging.RenderTargetBitmap(tb.PixelWidth, tb.PixelHeight, 96, 96, PixelFormats.Pbgra32);
bmp.Render(drawingVisual);
return bmp;
}
我已经编辑了你的标题。请看,如果一致意见是否定的,他们就不应该这样。你试过旋转图像控件吗?是的,这是XAML中的渲染变换。你解决了这个问题吗?