本文整理汇总了C#中Windows.Storage.Streams.InMemoryRandomAccessStream.Seek方法的典型用法代码示例。如果您正苦于以下问题:C# InMemoryRandomAccessStream.Seek方法的具体用法?C# InMemoryRandomAccessStream.Seek怎么用?C# InMemoryRandomAccessStream.Seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.Streams.InMemoryRandomAccessStream
的用法示例。
在下文中一共展示了InMemoryRandomAccessStream.Seek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadImageAsync
public async Task<BitmapSource> LoadImageAsync(Stream imageStream, Uri uri)
{
if (imageStream == null)
{
return null;
}
var stream = new InMemoryRandomAccessStream();
imageStream.CopyTo(stream.AsStreamForWrite());
stream.Seek(0);
BitmapImage bitmap = new BitmapImage();
await bitmap.SetSourceAsync(stream);
// convert to a writable bitmap so we can get the PixelBuffer back out later...
// in case we need to edit and/or re-encode the image.
WriteableBitmap bmp = new WriteableBitmap(bitmap.PixelHeight, bitmap.PixelWidth);
stream.Seek(0);
bmp.SetSource(stream);
List<Byte> allBytes = new List<byte>();
byte[] buffer = new byte[4000];
int bytesRead = 0;
while ((bytesRead = await imageStream.ReadAsync(buffer, 0, 4000)) > 0)
{
allBytes.AddRange(buffer.Take(bytesRead));
}
DataContainerHelper.Instance.WriteableBitmapToStorageFile(bmp, uri);
return bmp;
}
示例2: BlurElementAsync
/// <summary>
/// Applys a blur to a UI element
/// </summary>
/// <param name="sourceElement">UIElement to blur, generally an Image control, but can be anything</param>
/// <param name="blurAmount">Level of blur to apply</param>
/// <returns>Blurred UIElement as BitmapImage</returns>
public static async Task<BitmapImage> BlurElementAsync(this UIElement sourceElement, float blurAmount = 2.0f)
{
if (sourceElement == null)
return null;
var rtb = new RenderTargetBitmap();
await rtb.RenderAsync(sourceElement);
var buffer = await rtb.GetPixelsAsync();
var array = buffer.ToArray();
var displayInformation = DisplayInformation.GetForCurrentView();
using (var stream = new InMemoryRandomAccessStream())
{
var pngEncoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
pngEncoder.SetPixelData(BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Premultiplied,
(uint) rtb.PixelWidth,
(uint) rtb.PixelHeight,
displayInformation.RawDpiX,
displayInformation.RawDpiY,
array);
await pngEncoder.FlushAsync();
stream.Seek(0);
var canvasDevice = new CanvasDevice();
var bitmap = await CanvasBitmap.LoadAsync(canvasDevice, stream);
var renderer = new CanvasRenderTarget(canvasDevice,
bitmap.SizeInPixels.Width,
bitmap.SizeInPixels.Height,
bitmap.Dpi);
using (var ds = renderer.CreateDrawingSession())
{
var blur = new GaussianBlurEffect
{
BlurAmount = blurAmount,
Source = bitmap
};
ds.DrawImage(blur);
}
stream.Seek(0);
await renderer.SaveAsync(stream, CanvasBitmapFileFormat.Png);
var image = new BitmapImage();
await image.SetSourceAsync(stream);
return image;
}
}
示例3: Quadraliteral
public async void Quadraliteral(StorageFile file, IList<WF.Point> points)
{
var data = await FileIO.ReadBufferAsync(file);
OpencvImageProcess opencv = new OpencvImageProcess();
// create a stream from the file
var ms = new InMemoryRandomAccessStream();
var dw = new DataWriter(ms);
dw.WriteBuffer(data);
await dw.StoreAsync();
ms.Seek(0);
// find out how big the image is, don't need this if you already know
var bm = new BitmapImage();
await bm.SetSourceAsync(ms);
// create a writable bitmap of the right size
var wb = new WriteableBitmap(bm.PixelWidth, bm.PixelHeight);
ms.Seek(0);
// load the writable bitpamp from the stream
await wb.SetSourceAsync(ms);
Bitmap bmp = (Bitmap)wb;
var wb1 = opencv.GetImageCorners(wb);
wb1.Invalidate();
//wb.Invalidate();
// define quadrilateral's corners
//List<IntPoint> corners = new List<IntPoint>();
//foreach (var point in points)
//{
// corners.Add(new IntPoint((int)point.X, (int)point.Y));
//}
//// create filter
//var filter =
// new SimpleQuadrilateralTransformation(corners);
//// apply the filter
//Bitmap newImage = filter.Apply(bmp);
//wb = (WriteableBitmap)newImage;
var f = await this.WriteableBitmapToStorageFile(wb1, FileFormat.Jpeg);
}
示例4: Should_detect_corrupt_data
public async Task Should_detect_corrupt_data()
{
using (var input = new InMemoryRandomAccessStream())
{
await CopyData(input, "IO.HashedBlockStream.bin");
input.Seek(200);
await input.WriteAsync(CryptographicBuffer.GenerateRandom(8));
input.Seek(0);
await Assert.ThrowsAsync<InvalidDataException>(
() => HashedBlockFileFormat.Read(input));
}
}
示例5: Base64ToBitmapImage
public async Task<BitmapImage> Base64ToBitmapImage(string base64String)
{
BitmapImage img = new BitmapImage();
if (string.IsNullOrEmpty(base64String))
return img;
using (var ims = new InMemoryRandomAccessStream())
{
byte[] bytes = Convert.FromBase64String(base64String);
base64String = "";
using (DataWriter dataWriter = new DataWriter(ims))
{
dataWriter.WriteBytes(bytes);
bytes = null;
await dataWriter.StoreAsync();
ims.Seek(0);
await img.SetSourceAsync(ims); //not in RC
return img;
}
}
}
示例6: ConvertToGrayScale
public async Task<byte[]> ConvertToGrayScale(byte[] imageBytes, int height, int width)
{
using (InMemoryRandomAccessStream rasStream = new InMemoryRandomAccessStream())
{
await rasStream.WriteAsync(imageBytes.AsBuffer());
var decoder = await BitmapDecoder.CreateAsync(rasStream);
var pixelData = await decoder.GetPixelDataAsync();
var pixels = pixelData.DetachPixelData();
if (_filter == null)
_filter = new ImageFilter();
await _filter.ToGrayScale(pixels.AsBuffer());
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, rasStream);
encoder.SetPixelData(decoder.BitmapPixelFormat, BitmapAlphaMode.Ignore, (uint)width, (uint)height, decoder.DpiX, decoder.DpiY, pixels);
await encoder.FlushAsync();
using (BinaryReader br = new BinaryReader(rasStream.AsStreamForRead()))
{
rasStream.Seek(0);
return br.ReadBytes((int)rasStream.AsStreamForRead().Length);
}
}
}
示例7: ProccesImage
public async void ProccesImage(StorageFile imageFile)
{
var data = await FileIO.ReadBufferAsync(imageFile);
// create a stream from the file
var ms = new InMemoryRandomAccessStream();
var dw = new DataWriter(ms);
dw.WriteBuffer(data);
await dw.StoreAsync();
ms.Seek(0);
// find out how big the image is, don't need this if you already know
var bm = new BitmapImage();
await bm.SetSourceAsync(ms);
// create a writable bitmap of the right size
var wb = new WriteableBitmap(bm.PixelWidth, bm.PixelHeight);
ms.Seek(0);
// load the writable bitpamp from the stream
await wb.SetSourceAsync(ms);
Bitmap bmp = (Bitmap)wb;
//var filter1 = Grayscale.CommonAlgorithms.BT709;
//bmp = filter1.Apply(bmp);
wb = (WriteableBitmap)bmp;
var file = await this.WriteableBitmapToStorageFile(wb, FileFormat.Jpeg);
}
示例8: Page_Loaded
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
await InitializeQrCode();
var imgProp = new ImageEncodingProperties { Subtype = "BMP", Width = 600, Height = 800 };
var bcReader = new BarcodeReader();
while (true)
{
var stream = new InMemoryRandomAccessStream();
await _mediaCapture.CapturePhotoToStreamAsync(imgProp, stream);
stream.Seek(0);
var wbm = new WriteableBitmap(600, 800);
await wbm.SetSourceAsync(stream);
var result = bcReader.Decode(wbm);
if (result != null)
{
var msgbox = new MessageDialog(result.Text);
await msgbox.ShowAsync();
}
}
}
示例9: RenderToRandomAccessStream
public static async Task<IRandomAccessStream> RenderToRandomAccessStream(this UIElement element) {
var rtb = new RenderTargetBitmap();
await rtb.RenderAsync(element);
IBuffer pixelBuffer = await rtb.GetPixelsAsync();
byte[] pixels = pixelBuffer.ToArray();
// Useful for rendering in the correct DPI
DisplayInformation displayInformation = DisplayInformation.GetForCurrentView();
var stream = new InMemoryRandomAccessStream();
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, stream);
encoder.SetPixelData(BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Premultiplied,
(uint)rtb.PixelWidth,
(uint)rtb.PixelHeight,
displayInformation.RawDpiX,
displayInformation.RawDpiY,
pixels);
await encoder.FlushAsync();
stream.Seek(0);
return stream;
}
示例10: ResizeImage
async Task<WriteableBitmap> ResizeImage(WriteableBitmap baseWriteBitmap, uint width, uint height)
{
Stream stream = baseWriteBitmap.PixelBuffer.AsStream();
byte[] pixels = new byte[(uint)stream.Length];
await stream.ReadAsync(pixels, 0, pixels.Length);
var inMemoryRandomStream = new InMemoryRandomAccessStream();
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, inMemoryRandomStream);
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)baseWriteBitmap.PixelWidth, (uint)baseWriteBitmap.PixelHeight, 96, 96, pixels);
await encoder.FlushAsync();
var transform = new BitmapTransform
{
ScaledWidth = width,
ScaledHeight = height
};
inMemoryRandomStream.Seek(0);
var decoder = await BitmapDecoder.CreateAsync(inMemoryRandomStream);
var pixelData = await decoder.GetPixelDataAsync(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Straight,
transform,
ExifOrientationMode.IgnoreExifOrientation,
ColorManagementMode.DoNotColorManage);
var sourceDecodedPixels = pixelData.DetachPixelData();
var inMemoryRandomStream2 = new InMemoryRandomAccessStream();
var encoder2 = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, inMemoryRandomStream2);
encoder2.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, width, height, 96, 96, sourceDecodedPixels);
await encoder2.FlushAsync();
inMemoryRandomStream2.Seek(0);
var bitmap = new WriteableBitmap((int)width, (int)height);
await bitmap.SetSourceAsync(inMemoryRandomStream2);
return bitmap;
}
示例11: BeginReadCCTV
async void BeginReadCCTV()
{
IsBeginRead = true;
ISExit = false;
tblCCTV cctvinfo=null;
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
() =>
{
cctvinfo = this.DataContext as tblCCTV;
});
// client=new HttpClient();
while (!ISExit)
{
try
{
Uri uri = new Uri("http://192.192.161.3/" + cctvinfo.REF_CCTV_ID.Trim() + ".jpg?" + rnd.Next(), UriKind.Absolute);
using (httpClient = new HttpClient())
{
httpClient.Timeout = TimeSpan.FromSeconds(0.5);
var contentBytes = await httpClient.GetByteArrayAsync(uri);
var ims = new InMemoryRandomAccessStream();
var dataWriter = new DataWriter(ims);
dataWriter.WriteBytes(contentBytes);
await dataWriter.StoreAsync();
//ims.seak 0
ims.Seek(0 );
await Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal,()=>
{
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(ims );
this.imgCCTV.Source = bitmap;
imginx = (imginx + 1) % 90000;
this.RunFrameRate.Text = imginx.ToString();
});
}
}
catch (Exception ex)
{
// this.textBlock1.Text = ex.Message;
}
// BitmapImage img = new BitmapImage();
// img.SetSource(stream);
}
}
示例12: Should_read_correctly_formatted_stream
public async Task Should_read_correctly_formatted_stream()
{
using (var input = new InMemoryRandomAccessStream())
using (var expectedData = TestFiles.Read("IO.HashedBlockStream.Content.bin"))
{
await CopyData(input, "IO.HashedBlockStream.bin");
input.Seek(0);
expectedData.Seek(0);
using (var actualData = await HashedBlockFileFormat.Read(input))
{
Assert.Equal(expectedData.Size, (ulong)actualData.Length);
var actual = new byte[1024];
var expected = WindowsRuntimeBuffer.Create(actual.Length);
while (true)
{
expected = await expectedData.ReadAsync(expected);
var read = await actualData.ReadAsync(actual, 0, actual.Length);
Assert.Equal(expected.Length, (uint)read);
if (read == 0)
break;
Assert.Equal(expected.ToArray(), actual.Take(read));
}
}
}
}
示例13: Should_produce_read_bytes_hash
public async Task Should_produce_read_bytes_hash(int bufferSize)
{
var data = CryptographicBuffer.GenerateRandom(2048);
var expected = HashAlgorithmProvider
.OpenAlgorithm(HashAlgorithmNames.Sha256)
.HashData(data);
using (var file = new InMemoryRandomAccessStream())
{
await file.WriteAsync(data);
file.Seek(0);
var buffer = WindowsRuntimeBuffer.Create(bufferSize);
using (var hashed = new HashedInputStream(file))
{
for (var i = 0; i < 8; i++)
{
await hashed.ReadAsync(
buffer, buffer.Capacity);
}
var hash = hashed.GetHashAndReset();
Assert.Equal(expected.ToArray(), hash.ToArray());
}
}
}
示例14: ToQrDataUri
public async static Task<Uri> ToQrDataUri(this ISdp sdp, int width, int height)
{
var qrCodeWriter = new QRCodeWriter();
var bitMatrix = qrCodeWriter.encode(sdp.ToString(), ZXing.BarcodeFormat.QR_CODE, width, height);
using (var canvasRenderTarget = new CanvasRenderTarget(CanvasDevice.GetSharedDevice(), 500, 500, 96))
{
using (var drawingSession = canvasRenderTarget.CreateDrawingSession())
{
for (var y = 0; y < height; y++)
{
for (var x = 0; x < width; x++)
{
drawingSession.DrawRectangle(x, y, 1, 1, bitMatrix.get(x, y) ? Color.FromArgb(0, 0, 0, 0) : Color.FromArgb(255, 255, 255, 255));
}
}
}
using (var inMemoryRandomAccessStream = new InMemoryRandomAccessStream())
{
await canvasRenderTarget.SaveAsync(inMemoryRandomAccessStream, CanvasBitmapFileFormat.Png);
inMemoryRandomAccessStream.Seek(0);
var buffer = new byte[inMemoryRandomAccessStream.Size];
await inMemoryRandomAccessStream.ReadAsync(buffer.AsBuffer(), (uint)inMemoryRandomAccessStream.Size, InputStreamOptions.None);
return new Uri($"data:image/png;base64,{Convert.ToBase64String(buffer)}");
}
}
}
示例15: GetBijinPicture
private async void GetBijinPicture()
{
var date = DateTime.Now;
var url = "http://www.bijint.com/jp/tokei_images/" + date.ToString("HHmm") + ".jpg";
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Referrer = new Uri("http://www.bijint.com/jp/");
using (var strm = await client.GetStreamAsync(new Uri(url)))
{
// BitmapImageインスタンスへはStream型をそのまま読み込ませることができないため、
// InMemoryRandomAccessStreamへソースストリームをコピーする
InMemoryRandomAccessStream ims = new InMemoryRandomAccessStream();
var output = ims.GetOutputStreamAt(0);
await RandomAccessStream.CopyAsync(strm.AsInputStream(), output);
// BitmapImageへソースを設定し、Imageコントロールで表示させる
var bitmap = new BitmapImage();
bitmap.SetSource(ims);
image.Source = bitmap;
// Save用にbyte配列に保存
ims.Seek(0);
imageBuffer = new byte[ims.Size];
IBuffer ibuffer = imageBuffer.AsBuffer();
await ims.ReadAsync(ibuffer, (uint)ims.Size, InputStreamOptions.None);
}
}