本文整理汇总了C#中Windows.UI.Xaml.Media.Imaging.WriteableBitmap类的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap类的具体用法?C# WriteableBitmap怎么用?C# WriteableBitmap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WriteableBitmap类属于Windows.UI.Xaml.Media.Imaging命名空间,在下文中一共展示了WriteableBitmap类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ButtonFilePick_Click
private async void ButtonFilePick_Click(object sender, RoutedEventArgs e)
{
var picker = new FileOpenPicker();
picker.ViewMode = PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".jpg");
picker.FileTypeFilter.Add(".jpeg");
picker.FileTypeFilter.Add(".png");
StorageFile file = await picker.PickSingleFileAsync();
if (file != null)
{
ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync();
var savedPictureStream = await file.OpenAsync(FileAccessMode.Read);
//set image properties and show the taken photo
bitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height);
await bitmap.SetSourceAsync(savedPictureStream);
BBQImage.Source = bitmap;
BBQImage.Visibility = Visibility.Visible;
(this.DataContext as BBQRecipeViewModel).imageSource = file.Path;
}
}
开发者ID:cheahengsoon,项目名称:Windows10UWP-HandsOnLab,代码行数:27,代码来源:BBQRecipePage.xaml.cs
示例2: Device
public Device(WriteableBitmap bmp)
{
this.bmp = bmp;
// The back buffer size is equal to the number of pixels to draw
// on screen (width*height) * 4 (R,G,B & Alpha values).
backBuffer = new byte[bmp.PixelWidth * bmp.PixelHeight * 4];
}
开发者ID:shecodez,项目名称:Axion,代码行数:7,代码来源:Device.cs
示例3: FlagFactory
public FlagFactory()
{
/*
* CurrentPenStyle = 0 不画东西
* CurrentPenStyle = 1 油画棒风格
* CurrentPenStyle = 2 水彩风格
* CurrentPenStyle = 3 印章风格
* CurrentPenStyle = 4 橡皮擦
*/
CurrentPenStyle = 0;
CurrentPenColor = "";
CurrentOpacity = 100;
ScreenHeight = Window.Current.Bounds.Height;
ScreenWidth = Window.Current.Bounds.Width;
pointerDictionary = new Dictionary<uint, Polyline>();
MoveOut = false;
Pressed = false;
ReleaseAtOut = false;
IsDragingPic = false;
DragPic = null;
IsGetScreenSucccess = false;
strContent = "";
PainterHeight = ScreenHeight - 180;
PainterWidth = ScreenWidth - 80;
BitmapOutput = new WriteableBitmap((int)PainterWidth,(int)PainterHeight);
}
开发者ID:IcePlus,项目名称:KidsPainter,代码行数:28,代码来源:FlagFactory.cs
示例4: ToWriteableBitmap
private static unsafe WriteableBitmap ToWriteableBitmap(this BitmapHolder holder)
{
var writeableBitmap = new WriteableBitmap(holder.Width, holder.Height);
using (var stream = writeableBitmap.PixelBuffer.AsStream())
{
int length = holder.Pixels.Length;
var buffer = new byte[length * 4];
fixed (int* srcPtr = holder.Pixels)
{
var b = 0;
for (var i = 0; i < length; i++, b += 4)
{
var p = srcPtr[i];
buffer[b + 3] = (byte)((p >> 24) & 0xff);
buffer[b + 2] = (byte)((p >> 16) & 0xff);
buffer[b + 1] = (byte)((p >> 8) & 0xff);
buffer[b + 0] = (byte)(p & 0xff);
}
stream.Write(buffer, 0, length * 4);
}
}
return writeableBitmap;
}
开发者ID:nukedbit,项目名称:FFImageLoading,代码行数:27,代码来源:ImageExtensions.cs
示例5: OCRAsync
async Task<string> OCRAsync(byte[] buffer, uint width, uint height)
{
var bitmap = new WriteableBitmap((int)width, (int)height);
var memoryStream = new MemoryStream(buffer);
await bitmap.SetSourceAsync(memoryStream.AsRandomAccessStream());
if (bitmap.PixelHeight < 40 ||
bitmap.PixelHeight > 2600 ||
bitmap.PixelWidth < 40 ||
bitmap.PixelWidth > 2600)
bitmap = await ResizeImage(bitmap, (uint)(bitmap.PixelWidth * .7), (uint)(bitmap.PixelHeight * .7));
var ocrResult = await ocrEngine.RecognizeAsync((uint)bitmap.PixelHeight, (uint)bitmap.PixelWidth, bitmap.PixelBuffer.ToArray());
if (ocrResult.Lines != null)
{
var extractedText = new StringBuilder();
foreach (var line in ocrResult.Lines)
{
foreach (var word in line.Words)
extractedText.Append(word.Text + " ");
extractedText.Append(Environment.NewLine);
}
return extractedText.ToString();
}
return null;
}
开发者ID:SamirHafez,项目名称:Nutrition,代码行数:31,代码来源:WPOCRService.cs
示例6: OnNavigatedTo
protected override void OnNavigatedTo( NavigationEventArgs e )
{
base.OnNavigatedTo( e );
try {
// Kinectを開く
kinect = KinectSensor.GetDefault();
kinect.Open();
// 表示のためのデータを作成
depthFrameDesc = kinect.DepthFrameSource.FrameDescription;
// Depthリーダーを開く
depthFrameReader = kinect.DepthFrameSource.OpenReader();
depthFrameReader.FrameArrived += depthFrameReader_FrameArrived;
// 表示のためのデータ
depthBitmap = new WriteableBitmap( depthFrameDesc.Width,
depthFrameDesc.Height );
ImageDepth.Source = depthBitmap;
depthBuffer = new ushort[depthFrameDesc.LengthInPixels];
depthBitmapBuffer = new byte[depthFrameDesc.LengthInPixels * 4];
depthPoint = new Point( depthFrameDesc.Width / 2,
depthFrameDesc.Height / 2 );
}
catch ( Exception ex ) {
MessageDialog dlg = new MessageDialog(ex.Message);
dlg.ShowAsync();
}
}
开发者ID:noa99kee,项目名称:K4W2-Book,代码行数:32,代码来源:MainPage.xaml.cs
示例7: OnNavigatedTo
protected override void OnNavigatedTo( NavigationEventArgs e )
{
base.OnNavigatedTo( e );
try {
// Kinectを開く
kinect = KinectSensor.GetDefault();
if ( kinect == null ) {
throw new Exception( "Kinectを開けません" );
}
kinect.Open();
// 赤外線画像の情報を取得する
infraredFrameDesc = kinect.InfraredFrameSource.FrameDescription;
// 画像化のためのバッファを作成する
infraredBitmapBuffer = new byte[infraredFrameDesc.LengthInPixels * 4];
infraredBitmap = new WriteableBitmap(
infraredFrameDesc.Width, infraredFrameDesc.Height );
ImageInfrared.Source = infraredBitmap;
infraredBuffer = new ushort[infraredFrameDesc.LengthInPixels];
// 赤外線画像リーダーを開く
infraredFrameReader = kinect.InfraredFrameSource.OpenReader();
infraredFrameReader.FrameArrived += infraredFrameReader_FrameArrived;
}
catch ( Exception ex ) {
MessageDialog dlg = new MessageDialog( ex.Message );
dlg.ShowAsync();
}
}
开发者ID:noa99kee,项目名称:K4W2-Book,代码行数:33,代码来源:MainPage.xaml.cs
示例8: OnNavigatedTo
protected override void OnNavigatedTo( NavigationEventArgs e )
{
base.OnNavigatedTo( e );
try {
// Kinectを開く
kinect = KinectSensor.GetDefault();
if ( kinect == null ) {
throw new Exception( "Kinectを開けません" );
}
kinect.Open();
// カラー画像の情報を作成する(BGRAフォーマット)
colorFrameDesc = kinect.ColorFrameSource.CreateFrameDescription( ColorImageFormat.Bgra );
colorBitmap = new WriteableBitmap( colorFrameDesc.Width, colorFrameDesc.Height );
ImageColor.Source = colorBitmap;
colorBuffer = new byte[colorFrameDesc.Width * colorFrameDesc.Height * colorFrameDesc.BytesPerPixel];
// カラーリーダーを開く
colorFrameReader = kinect.ColorFrameSource.OpenReader();
colorFrameReader.FrameArrived += colorFrameReader_FrameArrived;
}
catch ( Exception ex ) {
MessageDialog dlg = new MessageDialog( ex.Message );
dlg.ShowAsync();
}
}
开发者ID:kaorun55,项目名称:Kinect-for-Windows-SDK-v2.0-Samples,代码行数:30,代码来源:MainPage.xaml.cs
示例9: Overlay
public static WriteableBitmap Overlay(WriteableBitmap bmp, WriteableBitmap overlay, Point location)
{
var result = bmp.Clone();
var size = new Size(overlay.PixelWidth, overlay.PixelHeight);
result.Blit(new Rect(location, size), overlay, new Rect(new Point(0, 0), size), WriteableBitmapExtensions.BlendMode.Alpha);
return result;
}
开发者ID:Narinyir,项目名称:WriteableBitmapEx,代码行数:7,代码来源:MainPage.xaml.cs
示例10: PageLoaded
private async void PageLoaded(object sender, RoutedEventArgs e)
{
var bmp = new WriteableBitmap(1024, 768);
imageControl.Source = bmp;
device = new RenderDevice(bmp);
camera = new Camera
{
Position = new Vector3(0, 0, 10.0f),
Target = Vector3.Zero
};
var importer = new BabylonImporter();
var importedMeshes = await importer.LoadFileAsync("model.babylon");
meshes = new List<Mesh>();
foreach(var mesh in importedMeshes)
meshes.Add(mesh);
foreach(var mesh in importedMeshes)
{
var newMesh = new Mesh("MonkeyClone", mesh.Vertices, mesh.Faces);
newMesh.Position = new Vector3(2.65f, 0, 0);
meshes.Add(newMesh);
}
CompositionTarget.Rendering += Render;
}
开发者ID:rthome,项目名称:softrender,代码行数:27,代码来源:MainPage.xaml.cs
示例11: OnNavigatedTo
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
StorageFile imgFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/1.jpg"));
using (IRandomAccessStream streamIn = await imgFile.OpenReadAsync())
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(BitmapDecoder.JpegDecoderId, streamIn);
// 获取像素数据
PixelDataProvider provd = await decoder.GetPixelDataAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Straight, new BitmapTransform(), ExifOrientationMode.IgnoreExifOrientation, ColorManagementMode.DoNotColorManage);
byte[] srcData = provd.DetachPixelData();
// 灰度处理
for (int i = 0; i < srcData.Length; i += 4)
{
double b = srcData[i];
double g = srcData[i + 1];
double r = srcData[i + 2];
double v = (b + g + r) / 3d;
srcData[i] = srcData[i + 1] = srcData[i + 2] = Convert.ToByte(v);
}
WriteableBitmap wbitmap = new WriteableBitmap((int)decoder.PixelWidth, (int)decoder.PixelHeight);
srcData.CopyTo(wbitmap.PixelBuffer);
this.imgGray.Source = wbitmap;
}
}
开发者ID:forehalo,项目名称:UWP-dev,代码行数:26,代码来源:MainPage.xaml.cs
示例12: Page_Loaded
private void Page_Loaded(object sender, RoutedEventArgs e)
{
// Choose the back buffer resolution here.
WriteableBitmap bmp = new WriteableBitmap(640, 480);
device = new Device(bmp);
// Image XAML control
frontBuffer.Source = bmp;
mesh.Vertices[0] = new Vector3(-1, 1, 1);
mesh.Vertices[1] = new Vector3(1, 1, 1);
mesh.Vertices[2] = new Vector3(-1, -1, 1);
mesh.Vertices[3] = new Vector3(-1, -1, -1);
mesh.Vertices[4] = new Vector3(-1, 1, -1);
mesh.Vertices[5] = new Vector3(1, 1, -1);
mesh.Vertices[6] = new Vector3(1, -1, 1);
mesh.Vertices[7] = new Vector3(1, -1, -1);
camera.Position = new Vector3(0, 0, 10.0f);
camera.Target = Vector3.Zero;
// Registering to the XAML rendering Loop
CompositionTarget.Rendering += CompositionTarget_Rendering;
}
开发者ID:shecodez,项目名称:Axion,代码行数:25,代码来源:MainPage.xaml.cs
示例13: StorageFileToWriteableBitmapWithDirection
public static async Task<WriteableBitmap> StorageFileToWriteableBitmapWithDirection(StorageFile file)
{
if (file == null)
return null;
using (IRandomAccessStream stream = await file.OpenReadAsync())
{
// Create a decoder from the stream. With the decoder, we can get
// the properties of the image.
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);
PixelDataProvider pix = await decoder.GetPixelDataAsync(
BitmapPixelFormat.Bgra8,
BitmapAlphaMode.Straight,
new BitmapTransform(),
ExifOrientationMode.RespectExifOrientation,
ColorManagementMode.DoNotColorManage);
byte[] pixels = pix.DetachPixelData();
WriteableBitmap Bmp = new WriteableBitmap((int)decoder.OrientedPixelWidth, (int)decoder.OrientedPixelHeight);
Stream pixStream = Bmp.PixelBuffer.AsStream();
pixStream.Write(pixels, 0, (int)(decoder.OrientedPixelWidth * decoder.OrientedPixelHeight * 4));
return Bmp;
}
}
开发者ID:chenjianwp,项目名称:UWP_ToolKit_CommonLibrary,代码行数:26,代码来源:ImageHelper.cs
示例14: 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
示例15: read
private static async Task<WriteableBitmap> read()
{
using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read))
{
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(BitmapDecoder.JpegDecoderId, stream);
uint width = decoder.PixelWidth;
uint height = decoder.PixelHeight;
if (angle % 180 != 0)
{
width = decoder.PixelHeight;
height = decoder.PixelWidth;
}
Dictionary<int, BitmapRotation> angles = new Dictionary<int, BitmapRotation>()
{
{ 0, BitmapRotation.None },
{ 90, BitmapRotation.Clockwise90Degrees },
{ 180, BitmapRotation.Clockwise180Degrees },
{ 270, BitmapRotation.Clockwise270Degrees },
{ 360, BitmapRotation.None }
};
BitmapTransform transform = new BitmapTransform();
transform.Rotation = angles[angle];
PixelDataProvider data = await decoder.GetPixelDataAsync(
BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, transform,
ExifOrientationMode.IgnoreExifOrientation, ColorManagementMode.DoNotColorManage);
bitmap = new WriteableBitmap((int)width, (int)height);
byte[] buffer = data.DetachPixelData();
using (Stream pixels = bitmap.PixelBuffer.AsStream())
{
pixels.Write(buffer, 0, (int)pixels.Length);
}
}
return bitmap;
}
开发者ID:RoguePlanetoid,项目名称:Windows-10-Universal-Windows-Platform,代码行数:34,代码来源:Library.cs
示例16: ToBitmapImageAsync
public unsafe async static Task<WriteableBitmap> ToBitmapImageAsync(this BitmapHolder holder)
{
if (holder == null || holder.Pixels == null)
return null;
var writeableBitmap = new WriteableBitmap(holder.Width, holder.Height);
using (var stream = writeableBitmap.PixelBuffer.AsStream())
{
int length = holder.Pixels.Length;
var buffer = new byte[length * 4];
fixed (int* srcPtr = holder.Pixels)
{
var b = 0;
for (var i = 0; i < length; i++, b += 4)
{
var p = srcPtr[i];
buffer[b + 3] = (byte)((p >> 24) & 0xff);
buffer[b + 2] = (byte)((p >> 16) & 0xff);
buffer[b + 1] = (byte)((p >> 8) & 0xff);
buffer[b + 0] = (byte)(p & 0xff);
}
stream.Write(buffer, 0, length * 4);
}
}
writeableBitmap.Invalidate();
return writeableBitmap;
}
开发者ID:zenjoy,项目名称:FFImageLoading,代码行数:31,代码来源:ImageExtensions.cs
示例17: WriteToStorageFile
private static async Task<FileUpdateStatus> WriteToStorageFile(WriteableBitmap bitmap, StorageFile file)
{
StorageFile sFile = file;
if (sFile != null)
{
CachedFileManager.DeferUpdates(sFile);
using (var fileStream = await sFile.OpenAsync(FileAccessMode.ReadWrite))
{
BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream);
Stream pixelStream = bitmap.PixelBuffer.AsStream();
byte[] pixels = new byte[pixelStream.Length];
await pixelStream.ReadAsync(pixels, 0, pixels.Length);
encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore,
(uint) bitmap.PixelWidth,
(uint) bitmap.PixelHeight,
96.0,
96.0,
pixels);
await encoder.FlushAsync();
}
FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(sFile);
return status;
}
return FileUpdateStatus.Failed;
}
开发者ID:EdiWang,项目名称:UWP-Helpers,代码行数:27,代码来源:BitmapExtensions.cs
示例18: RegisterTile
public async Task<bool> RegisterTile() {
var pairedBands = await BandClientManager.Instance.GetBandsAsync();
using (var bandClient = await BandClientManager.Instance.ConnectAsync(pairedBands[0])) {
var tiles = await bandClient.TileManager.GetTilesAsync();
var tileCapacity = await bandClient.TileManager.GetRemainingTileCapacityAsync();
var tileIconBitmap = new WriteableBitmap(46, 46);
var tileIcon = tileIconBitmap.ToBandIcon();
var tileGuid = Guid.NewGuid();
var tile = new BandTile(tileGuid) {
IsBadgingEnabled = true,
Name = "jcMSBWN",
TileIcon = tileIcon
};
await bandClient.TileManager.AddTileAsync(tile);
_setting.WriteSetting(SETTINGS.TILE_ID, tile.TileId);
}
return true;
}
开发者ID:jcapellman,项目名称:jcMSBWN,代码行数:27,代码来源:MainModel.cs
示例19: OnImageUrlChanged
private async void OnImageUrlChanged()
{
if (ImageUrl == null)
{
return;
}
var rass = RandomAccessStreamReference.CreateFromUri(new Uri(ImageUrl, UriKind.Absolute));
IRandomAccessStream stream = await rass.OpenReadAsync();
var decoder = await BitmapDecoder.CreateAsync(stream);
Rect bounds = Window.Current.Bounds;
//WriteableBitmap bmp = new WriteableBitmap((int)bounds.Width, (int)bounds.Height);
var displayWidth = Math.Min(decoder.PixelWidth, bounds.Width);
var displayHeight = Math.Min(decoder.PixelHeight, bounds.Height);
WriteableBitmap bmp = new WriteableBitmap((int)displayWidth, (int)displayHeight);
stream.Seek(0);
//var blurFilter = new BlurFilter(60);
using (var source = new RandomAccessStreamImageSource(stream))
using (var blurFilter = new LensBlurEffect(source, new LensBlurPredefinedKernel(LensBlurPredefinedKernelShape.Circle, 20)))
//using (var filterEffect = new FilterEffect(source) { Filters = new[] { blurFilter } })
using (var renderer = new WriteableBitmapRenderer(blurFilter, bmp))
{
bmp = await renderer.RenderAsync();
bmp.Invalidate();
BackgroundImage.Source = bmp;
}
}
开发者ID:powerytg,项目名称:prism,代码行数:33,代码来源:BlurImageView.xaml.cs
示例20: RunTriangleUpdaterAsync
private async void RunTriangleUpdaterAsync()
{
do
{
await _triangleUpdateRequired.WaitAsync();
if (_isLoaded)
{
var wb = new WriteableBitmap(
(int)trianglePicker.ActualWidth,
(int)trianglePicker.ActualHeight);
var wbHue = new WriteableBitmap(
(int)slidersPanel.ActualWidth - 80,
1);
var wbSaturation = new WriteableBitmap(
(int)slidersPanel.ActualWidth - 80,
1);
var wbLightness = new WriteableBitmap(
(int)slidersPanel.ActualWidth - 80,
1);
var wbRed = new WriteableBitmap(
(int)slidersPanel.ActualWidth - 80,
1);
var wbGreen = new WriteableBitmap(
(int)slidersPanel.ActualWidth - 80,
1);
var wbBlue = new WriteableBitmap(
(int)slidersPanel.ActualWidth - 80,
1);
var color = ColorExtensions.FromHsl(hueRing.Value, 1, 0.5);
await Task.WhenAll(
wb.RenderColorPickerSaturationValueTriangleAsync(hueRing.Value),
wbHue.RenderColorPickerHSLHueBarAsync(1.0, 0.5),
wbSaturation.RenderColorPickerHSLSaturationBarAsync(hueRing.Value, 0.5),
wbLightness.RenderColorPickerHSLLightnessBarAsync(hueRing.Value, 0.5),
wbRed.RenderColorPickerRGBRedBarAsync(color.G / 255.0, color.B / 255.0),
wbGreen.RenderColorPickerRGBGreenBarAsync(color.R / 255.0, color.B / 255.0),
wbBlue.RenderColorPickerRGBBlueBarAsync(color.R / 255.0, color.G / 255.0));
if (_isLoaded)
{
triangleBrush.ImageSource = wb;
hueBackground.ImageSource = wbHue;
saturationBackground.ImageSource = wbSaturation;
lightnessBackground.ImageSource = wbLightness;
redBackground.ImageSource = wbRed;
greenBackground.ImageSource = wbGreen;
blueBackground.ImageSource = wbBlue;
}
}
} while (_isLoaded);
}
开发者ID:xyzzer,项目名称:WinRTXamlToolkit,代码行数:60,代码来源:ColorPickerPrimitivesTestView.xaml.cs
注:本文中的Windows.UI.Xaml.Media.Imaging.WriteableBitmap类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论