本文整理汇总了C#中System.Byte.AsBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# Byte.AsBuffer方法的具体用法?C# Byte.AsBuffer怎么用?C# Byte.AsBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Byte
的用法示例。
在下文中一共展示了Byte.AsBuffer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnProcess
protected override void OnProcess(PixelRegion sourcePixelRegion, PixelRegion targetPixelRegion)
{
if(Mask == null)
{
//copy all pixel
Array.Copy(sourcePixelRegion.ImagePixels,targetPixelRegion.ImagePixels,sourcePixelRegion.ImagePixels.Length);
return;
}
//create grayscale buffer
var buffer = new Byte[(int)(sourcePixelRegion.Bounds.Width*sourcePixelRegion.Bounds.Height)];
//interface grayscale buffer
var bitmapMask = new Bitmap(
new Windows.Foundation.Size(sourcePixelRegion.Bounds.Width, sourcePixelRegion.Bounds.Height),
ColorMode.Gray8,
(uint)sourcePixelRegion.Bounds.Width,
buffer.AsBuffer());
//load grayscale buffer
Mask.GetBitmapAsync(bitmapMask,OutputOption.Stretch).AsTask().Wait();
sourcePixelRegion.ForEachRow((index, width, pos) =>
{
for (int x = 0; x < width; ++x, ++index)
{
uint color = sourcePixelRegion.ImagePixels[index];
// copy grayscale buffer to alpha channel
var a = buffer[index];
uint rgb = (color & 0x00FFFFFF);
targetPixelRegion.ImagePixels[index] = rgb | (uint)(a << 24);
}
});
}
示例2: SaveImageToCacheAndGetImage2
public static async Task<BitmapImage> SaveImageToCacheAndGetImage2(Byte[] imageArray, string fileName)
{
try
{
var folder = ApplicationData.Current.LocalFolder;
var file = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
var bitmapImage = new BitmapImage();
using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
await stream.WriteAsync(imageArray.AsBuffer());
stream.Seek(0);
await bitmapImage.SetSourceAsync(stream);
stream.Dispose();
}
return bitmapImage;
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
return null;
}
}
示例3: PostSocketRead
private void PostSocketRead(Int32 length)
{
try
{
var buffer = new Byte[length];
var asyncOperationWithProgress = _socket.InputStream.ReadAsync(buffer.AsBuffer(), (UInt32)length, InputStreamOptions.Partial);
asyncOperationWithProgress.Completed += (info, status) =>
{
switch (status)
{
case AsyncStatus.Completed:
case AsyncStatus.Error:
{
try
{
IBuffer results = info.GetResults();
OnDataReadCompletion(results.Length, DataReader.FromBuffer(results));
}
catch (Exception exception)
{
Debug.WriteLine(String.Concat("Read operation failed: ", exception.Message));
}
break;
}
}
};
}
catch (Exception exception1)
{
Debug.WriteLine(String.Concat("failed to post a read failed with error: ", exception1.Message));
}
}