isp*_*iro 1 c# xaml win-universal-app uwp uwp-xaml
使用旋转图像
image.RenderTransform = new RotateTransform()...
Run Code Online (Sandbox Code Playgroud)
几乎是即时的.另一方面,使用
bitmapEncoder.BitmapTransform.Rotation = BitmapRotation.Clockwise90Degrees...
Run Code Online (Sandbox Code Playgroud)
是多少慢(在FlushAsync()) -超过半秒.
这是为什么?有没有办法利用快速旋转来旋转位图?
第一个image.RenderTransform将使用硬件渲染渲染位图.(GPU)图像不旋转但会旋转/缩放显示.(将仅直接从视频记录中访问可见像素)
第二个将由CPU(所有像素)旋转图像本身.它将为结果创建新的内存.(非视频内存)
更新:
有没有办法使用GPU编辑位图?取决于您的需求:
如果你想使用GPU.您可以使用托管包装器(如Slim DX/Sharp DX)这需要很长时间才能获得结果.不要忘记,通过gpu对图像进行重新编程可能会导致质量丢失.
如果只想旋转图像(0,90,180,270)?您可以使用带有de ScanLine0选项的Bitmap类.(这是为了保持质量和尺寸),您可以创建一个快速实现.
看这里: 在C#中使用Bitmaps快速工作
我会创建一个algoritm foreach角度(0,90,180,270).因为您不想计算每个像素的x,y位置.像下面的东西..
小费:
试图失去乘法/除法.
/*This time we convert the IntPtr to a ptr*/
byte* scan0 = (byte*)bData.Scan0.ToPointer();
for (int i = 0; i < bData.Height; ++i)
{
for (int j = 0; j < bData.Width; ++j)
{
byte* data = scan0 + i * bData.Stride + j * bitsPerPixel / 8;
//data is a pointer to the first byte of the 3-byte color data
}
}
Run Code Online (Sandbox Code Playgroud)
变成这样的东西:
/*This time we convert the IntPtr to a ptr*/
byte* scan0 = (byte*)bData.Scan0.ToPointer();
byte* data = scan0;
int bytesPerPixel = bitsPerPixel / 8;
for (int i = 0; i < bData.Height; ++i)
{
byte* data2 = data;
for (int j = 0; j < bData.Width; ++j)
{
//data2 is a pointer to the first byte of the 3-byte color data
data2 += bytesPerPixel;
}
data += bData.Stride;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
365 次 |
| 最近记录: |