我有这个代码可以循环旋转图像(如本文round robin image rotation what is the best way to do in opencv中所述)
我对c#的代码如下:
private BitmapSource RoundRobinImage(BitmapSource inputImage, int noOfPixel)
{
var imageHeight = (int)inputImage.Height;
var imageWidth = (int)inputImage.Width;
var outputBitmap = new WriteableBitmap(inputImage);
int sect1Width = (noOfPixel > 0) ? noOfPixel : imageWidth + noOfPixel;
int sect2Width = imageWidth - sect1Width;
int bytesPerPixel = (inputImage.Format.BitsPerPixel + 7) / 8;
{
var sourceRect1 = new Int32Rect(0, 0, sect1Width, imageHeight);
int stride1 = bytesPerPixel * sect1Width;
var pixelBuffer1 = new byte[stride1 * imageHeight];
inputImage.CopyPixels(sourceRect1, pixelBuffer1, stride1, 0);
sourceRect1.X = sect2Width;
sourceRect1.Y = 0;
outputBitmap.WritePixels(sourceRect1, pixelBuffer1, stride1, 0);
}
{
var sourceRect2 = new Int32Rect(sect1Width, 0, sect2Width, imageHeight);
int stride2 = bytesPerPixel * sect2Width;
var pixelBuffer2 = new byte[stride2 * imageHeight];
inputImage.CopyPixels(sourceRect2, pixelBuffer2, stride2, 0);
sourceRect2.X = 0;
sourceRect2.Y = 0;
outputBitmap.WritePixels(sourceRect2, pixelBuffer2, stride2, 0);
}
return outputBitmap;
}
代码有效,但速度不快。有没有办法改善其性能并提高其速度?
我使用的是wpf和.net 4.5
答案 0 :(得分:1)
吨:
很多人都在考虑使用场景。我通常会认为除非你保存转动的图像,否则整个转弯并不聪明,因为WPF可以做 - 就像我说的那样 - 用变换。