本文整理汇总了C#中Windows.UI.Xaml.Media.Imaging.WriteableBitmap类的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap类的具体用法?C# WriteableBitmap怎么用?C# WriteableBitmap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WriteableBitmap类属于Windows.UI.Xaml.Media.Imaging命名空间,在下文中一共展示了WriteableBitmap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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];
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}