本文整理汇总了C#中Windows.Storage.Streams.IBuffer.AsStream方法的典型用法代码示例。如果您正苦于以下问题:C# IBuffer.AsStream方法的具体用法?C# IBuffer.AsStream怎么用?C# IBuffer.AsStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.Streams.IBuffer
的用法示例。
在下文中一共展示了IBuffer.AsStream方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveImage
/// <summary>
/// Save the primitive image and thumbnail image and return the Photo model with local url
/// </summary>
/// <param name="imageBuffer"></param>
/// <returns></returns>
public static async Task<Photo> SaveImage(IBuffer imageBuffer)
{
try
{
Photo photo = new Photo
{
CreatedTime = DateTime.UtcNow
};
AutoResizeConfiguration tbRC = null;
AutoResizeConfiguration pvRC = null;
Rect thumbnailRect;
Size pvSize;
using (var source = new BufferImageSource(imageBuffer))
{
var info = await source.GetInfoAsync();
//var thumbnailSize = ImageHelper.CalculateSize(info.ImageSize);
thumbnailRect = CalculateRect(info.ImageSize);
pvSize = CalculateSize(info.ImageSize);
tbRC = new AutoResizeConfiguration(ImageHelper.thumbnailMaxBytes, thumbnailMaxSize, new Size(0, 0), AutoResizeMode.Automatic, 0, ColorSpace.Yuv420);
pvRC = new AutoResizeConfiguration(ImageHelper.pvMaxBytes, pvSize, new Size(0, 0), AutoResizeMode.Automatic, 0, ColorSpace.Yuv420);
}
using (var store = IsolatedStorageFile.GetUserStoreForApplication())
{
//Get LocalPath
var localPath = AppResources.LocalImagePath;
if (!store.DirectoryExists(localPath))
{
store.CreateDirectory(localPath);
}
//Save the primitive bitmap file
using (var file = store.CreateFile(photo.LocalUri = localPath + @"\" + photo.Tag + @"_Raw"))
{
using (var localImage = imageBuffer.AsStream())
{
localImage.CopyTo(file);
file.Flush();
localImage.Close();
}
}
//Save Preview Image
if (pvRC != null)
{
//Resize the Image to priview image
var pvBuffer = await Nokia.Graphics.Imaging.JpegTools.AutoResizeAsync(imageBuffer, pvRC);
//Save Preview Image
using (var file = store.CreateFile(localPath + @"\" + photo.Tag + @"_Preview.jpg"))
{
photo.PreviewDetailUri = file.Name;
;
using (var localImage = pvBuffer.AsStream())
{
localImage.CopyTo(file);
file.Flush();
localImage.Close();
}
}
}
//Save thumbnail Image
if(tbRC != null)
{
//Crop to the square
var rb = await Reframe(imageBuffer, thumbnailRect);
//Resize the Image to thumbnail
var tb = await Nokia.Graphics.Imaging.JpegTools.AutoResizeAsync(rb, tbRC);
//Save thumbnail
using (var file = store.CreateFile(photo.LocalThumbnailUri = localPath + @"\" + photo.Tag + @"_Thumbnail.jpg"))
{
photo.ThumbnailDetailUri = file.Name;
using (var localImage = tb.AsStream())
{
localImage.CopyTo(file);
file.Flush();
localImage.Close();
}
}
}
}
return photo;
}
//.........这里部分代码省略.........
示例2: FromPixelBuffer
/// <summary>
/// Loads the data from a pixel buffer like the RenderTargetBitmap provides and returns a new WriteableBitmap.
/// </summary>
/// <param name="pixelBuffer">The source pixel buffer with the image data.</param>
/// <param name="width">The width of the image data.</param>
/// <param name="height">The height of the image data.</param>
/// <returns>A new WriteableBitmap containing the pixel data.</returns>
public static async Task<WriteableBitmap> FromPixelBuffer(IBuffer pixelBuffer, int width, int height)
{
// Copy to WriteableBitmap
var bmp = new WriteableBitmap(width, height);
using (var srcStream = pixelBuffer.AsStream())
{
using (var destStream = bmp.PixelBuffer.AsStream())
{
srcStream.Seek(0, SeekOrigin.Begin);
await srcStream.CopyToAsync(destStream);
}
return bmp;
}
}
示例3: HashData
public IBuffer HashData (IBuffer data)
{
if (data == null)
return new byte[HashLength].AsBuffer();
return this.context.ComputeHash (data.AsStream()).AsBuffer();
}
示例4: PixelBufferInfo
public PixelBufferInfo(IBuffer pixelBuffer)
{
this.pixelStream = pixelBuffer.AsStream();
this.Bytes = new byte[this.pixelStream.Length];
this.pixelStream.Seek(0, SeekOrigin.Begin);
this.pixelStream.Read(this.Bytes, 0, Bytes.Length);
//this.Pixels = bytes.ToPixels();
}
示例5: ConvertImageBufferToJpegBytes
protected async Task<byte[]> ConvertImageBufferToJpegBytes(IBuffer imageBuffer)
{
using (var stream = imageBuffer.AsStream().AsRandomAccessStream())
{
var decoder = await BitmapDecoder.CreateAsync(stream);
var pixels = await decoder.GetPixelDataAsync();
using (var output = new InMemoryRandomAccessStream())
{
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, output);
await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
encoder.SetPixelData(decoder.BitmapPixelFormat, BitmapAlphaMode.Ignore,
decoder.OrientedPixelWidth, decoder.OrientedPixelHeight, decoder.DpiX, decoder.DpiY, pixels.DetachPixelData());
});
await encoder.FlushAsync();
var buffer = WindowsRuntimeBuffer.Create((int)output.Size);
output.Seek(0);
await output.ReadAsync(buffer, (uint)output.Size, InputStreamOptions.None);
return buffer.ToArray();
}
}
}
示例6: BufferToStream
private Stream BufferToStream(IBuffer buffer)
{
return buffer.AsStream();
}
示例7: WriteAsync_AbstractStream
} // ReadAsync_AbstractStream
#endregion ReadAsync implementations
#region WriteAsync implementations
internal static IAsyncOperationWithProgress<UInt32, UInt32> WriteAsync_AbstractStream(Stream stream, IBuffer buffer)
{
Debug.Assert(stream != null);
Debug.Assert(stream.CanWrite);
Debug.Assert(buffer != null);
Contract.EndContractBlock();
// Choose the optimal writing strategy for the kind of buffer supplied:
Func<CancellationToken, IProgress<UInt32>, Task<UInt32>> writeOperation;
Byte[] data;
Int32 offset;
// If buffer is backed by a managed array:
if (buffer.TryGetUnderlyingData(out data, out offset))
{
writeOperation = async (cancelToken, progressListener) =>
{
if (cancelToken.IsCancellationRequested) // CancellationToken is non-nullable
return 0;
Debug.Assert(buffer.Length <= Int32.MaxValue);
Int32 bytesToWrite = (Int32)buffer.Length;
await stream.WriteAsync(data, offset, bytesToWrite, cancelToken).ConfigureAwait(continueOnCapturedContext: false);
if (progressListener != null)
progressListener.Report((UInt32)bytesToWrite);
return (UInt32)bytesToWrite;
};
// Otherwise buffer is of an unknown implementation:
}
else
{
writeOperation = async (cancelToken, progressListener) =>
{
if (cancelToken.IsCancellationRequested) // CancellationToken is non-nullable
return 0;
UInt32 bytesToWrite = buffer.Length;
Stream dataStream = buffer.AsStream();
Int32 buffSize = 0x4000;
if (bytesToWrite < buffSize)
buffSize = (Int32)bytesToWrite;
await dataStream.CopyToAsync(stream, buffSize, cancelToken).ConfigureAwait(continueOnCapturedContext: false);
if (progressListener != null)
progressListener.Report((UInt32)bytesToWrite);
return (UInt32)bytesToWrite;
};
} // if-else
// Construct and run the async operation:
return AsyncInfo.Run<UInt32, UInt32>(writeOperation);
} // WriteAsync_AbstractStream
示例8: WriteAsync
/// <summary>
/// Writes data asynchronously to a file.
/// </summary>
/// <param name="buffer">The buffer into which the asynchronous writer operation writes.</param>
/// <returns>The byte writer operation.</returns>
public IAsyncOperationWithProgress<uint, uint> WriteAsync(IBuffer buffer)
{
return ThreadPool.RunAsyncWithProgress<uint, uint>(p =>
{
buffer.AsStream().CopyTo(this.baseStream);
return buffer.Length;
});
}
示例9: Initialize
} // Initialize()
/// <summary>
/// Hashes the data.
/// </summary>
/// <param name="data">Data to be hashed.</param>
/// <returns>Hashed data.</returns>
public byte[] HashData(IBuffer data)
{
if (data == null)
{
throw new ArgumentNullException("data");
} // if
this.Initialize();
// cast IBuffer to something we can use
Stream stream = data.AsStream();
for (int o = 0; o < data.Length; o++)
{
// calculate CRC for next byte
// using table with 256 entries
this.crc = (ushort)((this.crc << 8) ^ Tab[(this.crc >> 8) ^ stream.ReadByte()]);
} // for
return this.HashFinal();
} // HashData()