本文整理汇总了C#中Windows.Storage.Streams.InMemoryRandomAccessStream类的典型用法代码示例。如果您正苦于以下问题:C# InMemoryRandomAccessStream类的具体用法?C# InMemoryRandomAccessStream怎么用?C# InMemoryRandomAccessStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InMemoryRandomAccessStream类属于Windows.Storage.Streams命名空间,在下文中一共展示了InMemoryRandomAccessStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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;
}
开发者ID:SamirHafez,项目名称:Nutrition,代码行数:32,代码来源:WPOCRService.cs
示例2: DrawStrokeOnImageBackground
public byte[] DrawStrokeOnImageBackground(IReadOnlyList<InkStroke> strokes, byte[] backgroundImageBuffer)
{
var stmbuffer = new InMemoryRandomAccessStream();
stmbuffer.AsStreamForWrite().AsOutputStream().WriteAsync(backgroundImageBuffer.AsBuffer()).AsTask().Wait();
CanvasDevice device = CanvasDevice.GetSharedDevice();
var canbit = CanvasBitmap.LoadAsync(device, stmbuffer, 96).AsTask().Result;
CanvasRenderTarget renderTarget = new CanvasRenderTarget(device, canbit.SizeInPixels.Width, canbit.SizeInPixels.Height, 96);
using (var ds = renderTarget.CreateDrawingSession())
{
ds.Clear(Colors.Transparent);
if (backgroundImageBuffer != null)
{
ds.DrawImage(canbit);
}
ds.DrawInk(strokes);
}
var stm = new InMemoryRandomAccessStream();
renderTarget.SaveAsync(stm, CanvasBitmapFileFormat.Png).AsTask().Wait();
var readfrom = stm.GetInputStreamAt(0).AsStreamForRead();
var ms = new MemoryStream();
readfrom.CopyTo(ms);
var outputBuffer = ms.ToArray();
return outputBuffer;
}
开发者ID:waynebaby,项目名称:GreaterShareUWP,代码行数:32,代码来源:DrawingService.cs
示例3: ImageToBytes
private async Task<byte[]> ImageToBytes(IRandomAccessStream sourceStream)
{
byte[] imageArray;
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(sourceStream);
var transform = new BitmapTransform { ScaledWidth = decoder.PixelWidth, ScaledHeight = decoder.PixelHeight };
PixelDataProvider pixelData = await decoder.GetPixelDataAsync(
BitmapPixelFormat.Rgba8,
BitmapAlphaMode.Straight,
transform,
ExifOrientationMode.RespectExifOrientation,
ColorManagementMode.DoNotColorManage);
using (var destinationStream = new InMemoryRandomAccessStream())
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, destinationStream);
encoder.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Premultiplied, decoder.PixelWidth,
decoder.PixelHeight, 96, 96, pixelData.DetachPixelData());
await encoder.FlushAsync();
BitmapDecoder outputDecoder = await BitmapDecoder.CreateAsync(destinationStream);
await destinationStream.FlushAsync();
imageArray = (await outputDecoder.GetPixelDataAsync()).DetachPixelData();
}
return imageArray;
}
开发者ID:orangpelupa,项目名称:PlayStation-App,代码行数:27,代码来源:AttachImageCommand.cs
示例4: OnDeferredImageRequestedHandler
private async void OnDeferredImageRequestedHandler(DataProviderRequest request)
{
// In this delegate we provide updated Bitmap data using delayed rendering.
if (_imageFile != null)
{
// If the delegate is calling any asynchronous operations it needs to acquire
// the deferral first. This lets the system know that you are performing some
// operations that might take a little longer and that the call to SetData
// could happen after the delegate returns. Once you acquired the deferral object
// you must call Complete on it after your final call to SetData.
DataProviderDeferral deferral = request.GetDeferral();
InMemoryRandomAccessStream inMemoryStream = new InMemoryRandomAccessStream();
// Make sure to always call Complete when finished with the deferral.
try
{
// Decode the image and re-encode it at 50% width and height.
IRandomAccessStream imageStream = await _imageFile.OpenAsync(FileAccessMode.Read);
BitmapDecoder imageDecoder = await BitmapDecoder.CreateAsync(imageStream);
BitmapEncoder imageEncoder = await BitmapEncoder.CreateForTranscodingAsync(inMemoryStream, imageDecoder);
imageEncoder.BitmapTransform.ScaledWidth = (uint)(imageDecoder.OrientedPixelWidth * 0.5);
imageEncoder.BitmapTransform.ScaledHeight = (uint)(imageDecoder.OrientedPixelHeight * 0.5);
await imageEncoder.FlushAsync();
request.SetData(RandomAccessStreamReference.CreateFromStream(inMemoryStream));
}
finally
{
deferral.Complete();
}
}
}
开发者ID:Prog-Party,项目名称:ProgParty.BoredPanda,代码行数:33,代码来源:ShareImage.cs
示例5: RenderUIElement
private async Task RenderUIElement(FrameworkElement elm, string fileName, int width, int height) {
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(1));
using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream())
{
var renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(elm);
var pixels = await renderTargetBitmap.GetPixelsAsync();
var logicalDpi = DisplayInformation.GetForCurrentView().LogicalDpi;
var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, ms);
encoder.SetPixelData(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Ignore,
(uint)renderTargetBitmap.PixelWidth,
(uint)renderTargetBitmap.PixelHeight,
logicalDpi,
logicalDpi,
pixels.ToArray());
await encoder.FlushAsync();
await X.Services.Image.Service.Instance.GenerateResizedImageAsync(width, elm.ActualWidth, elm.ActualHeight, ms, fileName + ".png", Services.Image.Service.location.TileFolder, height);
}
}
开发者ID:liquidboy,项目名称:X,代码行数:28,代码来源:TileEditor.xaml.cs
示例6: SaveResultToCameraRollAsync
/// <summary>
/// Asynchronously saves the <paramref name="photo" /> given to the camera roll album.
/// </summary>
/// <param name="photo">Photo to save.</param>
/// <returns>Image with thumbnail.</returns>
/// <exception cref="ArgumentNullException"><paramref name="photo"/> is <see langword="null"/>.</exception>
public async Task<IThumbnailedImage> SaveResultToCameraRollAsync(ICapturedPhoto photo)
{
if (photo == null)
{
throw new ArgumentNullException("photo");
}
Tracing.Trace("StorageService: Trying to save picture to the Camera Roll.");
Picture cameraRollPicture;
string name = this.GeneratePhotoName();
using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream())
{
// Convert image to JPEG format and rotate in accordance with the original photo orientation.
Tracing.Trace("StorageService: Converting photo to JPEG format. Size: {0}x{1}, Rotation: {2}", photo.Width, photo.Height, photo.Rotation);
byte[] pixelData = await photo.DetachPixelDataAsync();
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
encoder.BitmapTransform.Rotation = photo.Rotation;
encoder.BitmapTransform.Flip = photo.Flip;
encoder.IsThumbnailGenerated = true;
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, photo.Width, photo.Height, Constants.DefaultDpiX, Constants.DefaultDpiY, pixelData);
await encoder.FlushAsync();
cameraRollPicture = this.lazyMediaLibrary.Value.SavePictureToCameraRoll(name, stream.AsStream());
}
Tracing.Trace("StorageService: Saved to Camera Roll as {0}", name);
return new MediaLibraryThumbnailedImage(cameraRollPicture);
}
开发者ID:trilok567,项目名称:Windows-Phone,代码行数:39,代码来源:StorageService.cs
示例7: GetBijinPicture
public async Task<BitmapImage> GetBijinPicture(string Path)
{
var date = DateTime.Now;
var url = "http://www.bijint.com/" + Path + "/tokei_images/" + date.ToString("HHmm") + ".jpg";
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Referrer = new Uri("http://www.bijint.com/" + Path);
BitmapImage bitmap;
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コントロールで表示させる
bitmap = new BitmapImage();
bitmap.SetSource(ims);
}
return bitmap;
//var html = await client.GetStringAsync("http://www.bijint.com/kobe/cache/" + date.ToString("HHmm") + ".html");
//this.html.NavigateToString(html);
}
开发者ID:posaunehm,项目名称:MyBeautyClock,代码行数:25,代码来源:BeautyDataFactory.cs
示例8: bookmarkBtn_Click
/// <summary>
/// This is the click handler for the 'Solution' button.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private async void bookmarkBtn_Click(object sender, RoutedEventArgs e)
{
InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
await webView8.CapturePreviewToStreamAsync(ms);
//Create a small thumbnail
int longlength = 180, width = 0, height = 0;
double srcwidth = webView8.ActualWidth, srcheight = webView8.ActualHeight;
double factor = srcwidth / srcheight;
if (factor < 1)
{
height = longlength;
width = (int)(longlength * factor);
}
else
{
width = longlength;
height = (int)(longlength / factor);
}
BitmapSource small = await resize(width, height, ms);
BookmarkItem item = new BookmarkItem();
item.Title = webView8.DocumentTitle;
item.PageUrl = webView8.Source;
item.Preview = small;
bookmarks.Add(item);
}
开发者ID:ckc,项目名称:WinApp,代码行数:33,代码来源:Scenario8_CaptureBitmap.xaml.cs
示例9: ReadAsync
/// <summary>
/// Continuously look for a QR code
/// NOTE: this method won't work if recording is enabled ('hey Cortana, start recording' thing).
/// </summary>
public static async Task<string> ReadAsync(CancellationToken token = default(CancellationToken))
{
var mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync();
await mediaCapture.AddVideoEffectAsync(new MrcVideoEffectDefinition(), MediaStreamType.Photo);
var reader = new BarcodeReader();
reader.Options.TryHarder = false;
while (!token.IsCancellationRequested)
{
var imgFormat = ImageEncodingProperties.CreateJpeg();
using (var ras = new InMemoryRandomAccessStream())
{
await mediaCapture.CapturePhotoToStreamAsync(imgFormat, ras);
var decoder = await BitmapDecoder.CreateAsync(ras);
using (var bmp = await decoder.GetSoftwareBitmapAsync())
{
Result result = await Task.Run(() =>
{
var source = new SoftwareBitmapLuminanceSource(bmp);
return reader.Decode(source);
});
if (!string.IsNullOrEmpty(result?.Text))
return result.Text;
}
}
await Task.Delay(DelayBetweenScans);
}
return null;
}
开发者ID:xamarin,项目名称:urho-samples,代码行数:35,代码来源:QrCodeReader.cs
示例10: 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);
}
}
开发者ID:KarinoTaro,项目名称:MetroDokei,代码行数:27,代码来源:MainPage.xaml.cs
示例11: 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;
}
开发者ID:acedened,项目名称:TheChan,代码行数:25,代码来源:UIExtensions.cs
示例12: ConvertToRandomAccessStream
public static async Task<IRandomAccessStream> ConvertToRandomAccessStream(Stream source)
{
Stream streamToConvert = null;
if (!source.CanRead)
throw new Exception("The source cannot be read.");
if (!source.CanSeek)
{
var memStream = new MemoryStream();
await source.CopyToAsync(memStream);
streamToConvert = memStream;
}
else
{
streamToConvert = source;
}
var reader = new DataReader(streamToConvert.AsInputStream());
streamToConvert.Position = 0;
await reader.LoadAsync((uint) streamToConvert.Length);
var buffer = reader.ReadBuffer((uint) streamToConvert.Length);
var randomAccessStream = new InMemoryRandomAccessStream();
var outputStream = randomAccessStream.GetOutputStreamAt(0);
await outputStream.WriteAsync(buffer);
await outputStream.FlushAsync();
return randomAccessStream;
}
开发者ID:bendewey,项目名称:LeadPro,代码行数:30,代码来源:ImageStreamConverter.cs
示例13: FromStream
internal static Bitmap FromStream(Stream stream)
{
Bitmap bitmap = null;
Task.Run(async () =>
{
using (var raStream = new InMemoryRandomAccessStream())
{
await stream.CopyToAsync(raStream.AsStream());
var decoder = await BitmapDecoder.CreateAsync(raStream);
var pixelData = await decoder.GetPixelDataAsync();
var width = (int)decoder.OrientedPixelWidth;
var height = (int)decoder.OrientedPixelHeight;
const PixelFormat format = PixelFormat.Format32bppArgb;
var bytes = pixelData.DetachPixelData();
bitmap = new Bitmap(width, height, format);
var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, format);
Marshal.Copy(bytes, 0, data.Scan0, bytes.Length);
bitmap.UnlockBits(data);
}
}).Wait();
return bitmap;
}
开发者ID:hungdluit,项目名称:aforge,代码行数:26,代码来源:Bitmap.Store.cs
示例14: 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);
}
}
开发者ID:ufjl0683,项目名称:sshmc,代码行数:60,代码来源:CCTV.xaml.cs
示例15: RenderToBase64
public async Task<string> RenderToBase64(UIElement element)
{
RenderTargetBitmap rtb = new RenderTargetBitmap();
await rtb.RenderAsync(element);
var pixelBuffer = await rtb.GetPixelsAsync();
var pixels = pixelBuffer.ToArray();
// Useful for rendering in the correct DPI
var displayInformation = DisplayInformation.GetForCurrentView();
var stream = new InMemoryRandomAccessStream();
var 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);
// read bytes
var bytes = new byte[stream.Size];
await stream.AsStream().ReadAsync(bytes, 0, bytes.Length);
// create base64
return Convert.ToBase64String(bytes);
}
开发者ID:dachibox,项目名称:UWP-Samples,代码行数:31,代码来源:MainViewModel.cs
示例16: 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();
}
}
}
开发者ID:ddumic,项目名称:WP_8_1_helper,代码行数:25,代码来源:QRCode.xaml.cs
示例17: GetBijinInfo
// TODO: 一分ごとに画像と名前を取得する
private async void GetBijinInfo()
{
var date = this.Current;
getKawaii(this.path + this.Current.ToString("HHmm"));
var url = "http://www.bijint.com/" + Path + "/tokei_images/" + date.ToString("HHmm") + ".jpg";
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Referrer = new Uri("http://www.bijint.com/" + path);
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);
this.Image = bitmap;
}
var html = await client.GetStringAsync("http://www.bijint.com/" + Path + "/cache/" + date.ToString("HHmm") + ".html");
var lines = html.Split('\n').Select(input => input.Trim()).Where(input => input != "\r" || input != "").ToList();
var nameLineIndex = lines.IndexOf("<thead>") + 2;
var nameLine = lines[nameLineIndex];
var temp = nameLine.Substring(0, nameLine.Length - 5);
var lastEnd = temp.LastIndexOf('>');
this.Subtitle = temp.Substring(lastEnd + 1);
}
开发者ID:posaunehm,项目名称:MyBeautyClock,代码行数:35,代码来源:SampleDataItem.cs
示例18: AsRandomAccessStreamAsync
public async static Task<IRandomAccessStream> AsRandomAccessStreamAsync(this Stream stream)
{
Stream streamToConvert = null;
if (!stream.CanRead)
{
throw new Exception("Cannot read the source stream-");
}
if (!stream.CanSeek)
{
MemoryStream memoryStream = new MemoryStream();
await stream.CopyToAsync(memoryStream);
streamToConvert = memoryStream;
}
else
{
streamToConvert = stream;
}
DataReader dataReader = new DataReader(streamToConvert.AsInputStream());
streamToConvert.Position = 0;
await dataReader.LoadAsync((uint)streamToConvert.Length);
IBuffer buffer = dataReader.ReadBuffer((uint)streamToConvert.Length);
InMemoryRandomAccessStream randomAccessStream = new InMemoryRandomAccessStream();
IOutputStream outputstream = randomAccessStream.GetOutputStreamAt(0);
await outputstream.WriteAsync(buffer);
await outputstream.FlushAsync();
return randomAccessStream;
}
开发者ID:uwe-e,项目名称:BSE.Tunes,代码行数:31,代码来源:StreamExtensions.cs
示例19: 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;
}
开发者ID:wpFaizK,项目名称:Windows-Universal-UWP-,代码行数:32,代码来源:DownloadHelper.cs
示例20: Button_Click_2
private async void Button_Click_2(object sender, RoutedEventArgs e)
{
var mem = new InMemoryRandomAccessStream();
var enc = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, mem);
int width = 140, height = 140;
int plane = 4;
byte[] data = new byte[width * height * plane];
int offset = 0;
for (int y = 0; y < width; y++)
{
for (int x = 0; x < height; x++)
{
data[offset + 0] = 0xFF; // R
data[offset + 1] = 0x00; // G
data[offset + 2] = 0x00; // B
data[offset + 3] = 0xFF; // Alpha
offset += 4;
}
}
enc.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight,
(uint)width, (uint)height, 96, 96, data);
await enc.FlushAsync();
BitmapImage bmp = new BitmapImage();
bmp.SetSource(mem);
image1.Source = bmp;
}
开发者ID:moonmile,项目名称:win8,代码行数:28,代码来源:BlankPage.xaml.cs
注:本文中的Windows.Storage.Streams.InMemoryRandomAccessStream类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论