本文整理汇总了C#中Windows.UI.Xaml.Media.Imaging.WriteableBitmap.Resize方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.Resize方法的具体用法?C# WriteableBitmap.Resize怎么用?C# WriteableBitmap.Resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.UI.Xaml.Media.Imaging.WriteableBitmap
的用法示例。
在下文中一共展示了WriteableBitmap.Resize方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EffectVignetting
public static WriteableBitmap EffectVignetting(this WriteableBitmap bmp, WriteableBitmap maskBmp, double vignetting)
{
// マスク画像を元画像のサイズにリサイズする
var resizedBmp = maskBmp.Resize(bmp.PixelWidth, bmp.PixelHeight);
return Effect(bmp, new VignettingEffect(resizedBmp, vignetting));
}
示例2: DisplayImage
/// <summary>
/// Displays an image on the LED matrix
/// </summary>
/// <param name="image">Bitmap to display on the LED matrix</param>
/// <returns>Task for tracking the status of the async call</returns>
public async Task DisplayImage(WriteableBitmap image)
{
WriteableBitmap resizedBitmap = image.Resize(
this.PixelWidth,
this.PixelHeight,
WriteableBitmapExtensions.Interpolation.Bilinear);
List<Color> colors = resizedBitmap.Flip(WriteableBitmapExtensions.FlipMode.Horizontal).ToColorList();
colors = colors.FlipEvenColumns(this.PixelHeight);
List<Color> perceptualColors = colors.Select(
color => color.ToPerceptual().ApplyGamma(1.5)).ToList();
colors.Clear();
colors.AddRange(perceptualColors);
colors.RemoveAt(MagicPixel);
IEnumerable<byte> bytes = colors.Get21BitPixelBytes();
App.Firmata.sendSysex(LED_RESET, new Buffer(0));
await Task.Delay(1);
App.Firmata.SendPixelBlob(bytes, 30);
await Task.Delay(1);
App.Firmata.sendSysex(LED_RESET, new Buffer(0));
await Task.Delay(1);
}
示例3: EffectBakumatsu
public static WriteableBitmap EffectBakumatsu(this WriteableBitmap bmp, WriteableBitmap maskBmp)
{
// マスク画像を元画像のサイズにリサイズする
var resizedBmp = maskBmp.Resize(bmp.PixelWidth, bmp.PixelHeight);
return Effect(bmp, new BakumatsuEffect(resizedBmp));
}
示例4: EffectToycamera
public static WriteableBitmap EffectToycamera(this WriteableBitmap bmp, WriteableBitmap maskBmp)
{
// マスク画像を元画像のサイズにリサイズする
var resizedBmp = maskBmp.Resize(bmp.PixelWidth, bmp.PixelHeight);
// コントラスト調整、彩度調整、口径食風処理のエフェクトオブジェクトを作成
var effectors = new List<IEffect>();
effectors.Add(new ContrastEffect(0.8));
effectors.Add(new SaturationEffect(0.7));
effectors.Add(new VignettingEffect(resizedBmp, 0.8));
// 複数のエフェクト処理を実行する
return Effect(bmp, effectors);
}
示例5: scaleBitmapDown
private static WriteableBitmap scaleBitmapDown(WriteableBitmap bitmap)
{
int minDimension = Math.Min(bitmap.PixelWidth, bitmap.PixelHeight);
if (minDimension <= CALCULATE_BITMAP_MIN_DIMENSION)
{
// If the bitmap is small enough already, just return it
return bitmap;
}
float scaleRatio = CALCULATE_BITMAP_MIN_DIMENSION / (float)minDimension;
WriteableBitmap resizedBitmap = bitmap.Resize((Int32)(bitmap.PixelWidth * scaleRatio), (Int32)(bitmap.PixelHeight * scaleRatio), WriteableBitmapExtensions.Interpolation.Bilinear);
return resizedBitmap;
}
示例6: DisplayImage
/// <summary>
/// Displays an image on the LED matrix
/// </summary>
/// <param name="image">Bitmap to display on the LED matrix</param>
/// <returns>Task for tracking the status of the async call</returns>
public async Task DisplayImage(WriteableBitmap image)
{
WriteableBitmap resizedBitmap = image.Resize(
this.PixelHeight,
this.PixelWidth,
WriteableBitmapExtensions.Interpolation.Bilinear);
List<Color> colors = resizedBitmap.ToColorList();
//colors.ForEach(c => colorsAdjusted.Add(c.ApplyGamma(1.5)));
//colors.ForEach(c => colorsAdjusted.Add(c.ToPerceptual()));
IEnumerable<byte> bytes = colors.Get21BitPixelBytes();
App.Firmata.SendPixelBlob(bytes, 30);
}
示例7: LoadImage
/// <summary>
/// Loads image from file to bitmap and displays it in UI.
/// </summary>
public async Task LoadImage(StorageFile file)
{
ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync();
bool sourceSet = false;
using (var imgStream = await file.OpenAsync(FileAccessMode.Read))
{
bitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height);
bitmap.SetSource(imgStream);
if (imgProp.Width > 2600 || imgProp.Height > 2600)
{
double scale = 1.0;
if (imgProp.Height > 2600)
scale = 2600.0 / imgProp.Height;
else if (imgProp.Width > 2600)
scale = Math.Min(scale, 2600.0 / imgProp.Width);
bitmap = bitmap.Resize((int)(imgProp.Width * scale), (int)(imgProp.Height * scale), WriteableBitmapExtensions.Interpolation.Bilinear);
}
}
ExtractText();
}
示例8: CreatePictrue
public void CreatePictrue(WriteableBitmap source)
{
pictrueshow.Source = source;
pictrueshow.UpdateLayout();
int i = 0;
for (int w = 0; w < GameGlobal.MaxTilesW; w++)
{
for (int h = 0; h < GameGlobal.MaxTilesH; h++)
{
var tile = Tiles.Children[i] as Tile;
WriteableBitmap temp = source.Resize((int)Tiles.Width, (int)Tiles.Height, WriteableBitmapExtensions.Interpolation.Bilinear);
var rect = new Rect(w * GameGlobal.TileW, h * GameGlobal.TileH, (int)GameGlobal.TileW, (int)GameGlobal.TileH);
temp = temp.Crop(rect);
temp.Invalidate();
tile.IndexX = tile.CorrectIndexX = w;
tile.IndexY = tile.CorrectIndexY = h;
tile.ImageSource = temp;
i += 1;
}
}
foreach (Tile item in Tiles.Children)
{
var r = GameGlobal.Random.Next(Tiles.Children.Count);
var temp = Tiles.Children[r] as Tile;
var x = temp.IndexX;
var y = temp.IndexY;
temp.IndexX = item.IndexX;
temp.IndexY = item.IndexY;
item.IndexX = x;
item.IndexY = y;
}
ANI_Starting.Begin();
}
示例9: LoadWallpaperArt
private async void LoadWallpaperArt()
{
if (_loaded ||
!App.Locator.AppSettingsHelper.Read("WallpaperArt", true, SettingsStrategy.Roaming)) return;
var wait = App.Locator.AppSettingsHelper.Read<int>("WallpaperDayWait");
var created = App.Locator.AppSettingsHelper.ReadJsonAs<DateTime>("WallpaperCreated");
// Set the image brush
var imageBrush = new ImageBrush { Opacity = .25, Stretch = Stretch.UniformToFill, AlignmentY = AlignmentY.Top};
LayoutGrid.Background = imageBrush;
// Once a week remake the wallpaper
if ((DateTime.Now - created).TotalDays > wait)
{
var albums =
App.Locator.CollectionService.Albums.ToList()
.Where(p => p.HasArtwork)
.ToList();
var albumCount = albums.Count;
if (albumCount < 10) return;
var h = Window.Current.Bounds.Height;
var rows = (int) Math.Ceiling(h/(ActualWidth/5));
const int collumns = 5;
var albumSize = (int) Window.Current.Bounds.Width/collumns;
var numImages = rows*5;
var imagesNeeded = numImages - albumCount;
var shuffle = await Task.FromResult(albums
.Shuffle()
.Take(numImages > albumCount ? albumCount : numImages)
.ToList());
if (imagesNeeded > 0)
{
var repeatList = new List<Album>();
while (imagesNeeded > 0)
{
var takeAmmount = imagesNeeded > albumCount ? albumCount : imagesNeeded;
await Task.Run(() => repeatList.AddRange(shuffle.Shuffle().Take(takeAmmount)));
imagesNeeded -= shuffle.Count;
}
shuffle.AddRange(repeatList);
}
// Initialize an empty WriteableBitmap.
var destination = new WriteableBitmap((int) Window.Current.Bounds.Width,
(int) Window.Current.Bounds.Height);
var col = 0; // Current Column Position
var row = 0; // Current Row Position
destination.Clear(Colors.Black); // Set the background color of the image to black
// will be copied
foreach (var artworkPath in shuffle.Select(album => string.Format(AppConstant.ArtworkPath, album.Id)))
{
var file = await WinRtStorageHelper.GetFileAsync(artworkPath);
// Read the image file into a RandomAccessStream
using (var fileStream = await file.OpenReadAsync())
{
try
{
// Now that you have the raw bytes, create a Image Decoder
var decoder = await BitmapDecoder.CreateAsync(fileStream);
// Get the first frame from the decoder because we are picking an image
var frame = await decoder.GetFrameAsync(0);
// Convert the frame into pixels
var pixelProvider = await frame.GetPixelDataAsync();
// Convert pixels into byte array
var srcPixels = pixelProvider.DetachPixelData();
var wid = (int) frame.PixelWidth;
var hgt = (int) frame.PixelHeight;
// Create an in memory WriteableBitmap of the same size
var bitmap = new WriteableBitmap(wid, hgt); // Temporary bitmap into which the source
using (var pixelStream = bitmap.PixelBuffer.AsStream())
{
pixelStream.Seek(0, SeekOrigin.Begin);
// Push the pixels from the original file into the in-memory bitmap
await pixelStream.WriteAsync(srcPixels, 0, srcPixels.Length);
bitmap.Invalidate();
// Resize the in-memory bitmap and Blit (paste) it at the correct tile
// position (row, col)
destination.Blit(new Rect(col*albumSize, row*albumSize, albumSize, albumSize),
bitmap.Resize(albumSize, albumSize, WriteableBitmapExtensions.Interpolation.Bilinear),
new Rect(0, 0, albumSize, albumSize));
//.........这里部分代码省略.........
示例10: CreateCollage
async Task CreateCollage(IReadOnlyList<StorageFile> files)
{
progressIndicator.Visibility = Windows.UI.Xaml.Visibility.Visible;
var sampleDataGroups = files;
if (sampleDataGroups.Count() == 0) return;
try
{
// Do a square-root of the number of images to get the
// number of images on x and y axis
int number = (int)Math.Ceiling(Math.Sqrt((double)files.Count));
// Calculate the width of each small image in the collage
int numberX = (int)(ImageCollage.ActualWidth / number);
int numberY = (int)(ImageCollage.ActualHeight / number);
// Initialize an empty WriteableBitmap.
WriteableBitmap destination = new WriteableBitmap(numberX * number, numberY * number);
int col = 0; // Current Column Position
int row = 0; // Current Row Position
destination.Clear(Colors.White); // Set the background color of the image to white
WriteableBitmap bitmap; // Temporary bitmap into which the source
// will be copied
foreach (var file in files)
{
// Create RandomAccessStream reference from the current selected image
RandomAccessStreamReference streamRef = RandomAccessStreamReference.CreateFromFile(file);
int wid = 0;
int hgt = 0;
byte[] srcPixels;
// Read the image file into a RandomAccessStream
using (IRandomAccessStreamWithContentType fileStream = await streamRef.OpenReadAsync())
{
// Now that you have the raw bytes, create a Image Decoder
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream);
// Get the first frame from the decoder because we are picking an image
BitmapFrame frame = await decoder.GetFrameAsync(0);
// Convert the frame into pixels
PixelDataProvider pixelProvider = await frame.GetPixelDataAsync();
// Convert pixels into byte array
srcPixels = pixelProvider.DetachPixelData();
wid = (int)frame.PixelWidth;
hgt = (int)frame.PixelHeight;
// Create an in memory WriteableBitmap of the same size
bitmap = new WriteableBitmap(wid, hgt);
Stream pixelStream = bitmap.PixelBuffer.AsStream();
pixelStream.Seek(0, SeekOrigin.Begin);
// Push the pixels from the original file into the in-memory bitmap
pixelStream.Write(srcPixels, 0, (int)srcPixels.Length);
bitmap.Invalidate();
if (row < number)
{
// Resize the in-memory bitmap and Blit (paste) it at the correct tile
// position (row, col)
destination.Blit(new Rect(col * numberX, row * numberY, numberX, numberY),
bitmap.Resize(numberX, numberY, WriteableBitmapExtensions.Interpolation.Bilinear),
new Rect(0, 0, numberX, numberY));
col++;
if (col >= number)
{
row++;
col = 0;
}
}
}
}
ImageCollage.Source = destination;
((WriteableBitmap)ImageCollage.Source).Invalidate();
progressIndicator.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
catch (Exception ex)
{
// TODO: Log Error, unable to render image
throw;
}
}
示例11: AppBarBtnEdit_Click
///////////////////////////////////////////////////////////////////////////
// Use the Nokia Imaging SDK to apply a filter to a selected image
private async void AppBarBtnEdit_Click(object sender, RoutedEventArgs e)
{
progressRing.IsEnabled = true;
progressRing.IsActive = true;
progressRing.Visibility = Visibility.Visible;
// Create NOK Imaging SDK effects pipeline and run it
var imageStream = new BitmapImageSource(originalBitmap.AsBitmap());
using (var effect = new FilterEffect(imageStream))
{
var filter = new Lumia.Imaging.Adjustments.GrayscaleFilter();
effect.Filters = new[] { filter };
// Render the image to a WriteableBitmap.
var renderer = new WriteableBitmapRenderer(effect, originalBitmap);
editedBitmap = await renderer.RenderAsync();
editedBitmap.Invalidate();
}
Image.Source = originalBitmap;
Image.Visibility = Visibility.Collapsed;
//Resizing the editedBitmap to 128x128
var resized1 = editedBitmap.Resize(128, 128, Windows.UI.Xaml.Media.Imaging.WriteableBitmapExtensions.Interpolation.Bilinear);
//converting the editedBitmap to byte array
byte[] edit_arr = resized1.ToByteArray();
//obtaining the images folder
StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder subfolder = await folder.GetFolderAsync("Images");
//create list of all the files in the images folder
var pictures = await subfolder.GetFilesAsync();
double ldiff = 50;//least percentage difference for an image to be a match
string dispText = "Try again";//default message to be displayed
byte threshold = 124;
//process through all images
foreach (var file in pictures)
{
if (file != null)
{
// Use WriteableBitmapEx to easily load image from a stream
using (var stream = await file.OpenReadAsync())
{
listBitmap = await new WriteableBitmap(1, 1).FromStream(stream);
stream.Dispose();
}
//convert obtained image to byte array
byte[] list_arr = listBitmap.ToByteArray();
byte[] difference = new byte[edit_arr.Length];
//compare byte array of both the images
for (int i=0;i<list_arr.Length;i++)
{
difference[i] = (byte)Math.Abs(edit_arr[i]-list_arr[i]);
}
//calculate percentage difference
int differentPixels = 0;
foreach(byte b in difference )
{
if (b > threshold)
differentPixels++;
}
double percentage = (double)differentPixels / (double)list_arr.Length;
percentage = percentage * 100;
if (percentage <= ldiff)
{
ldiff = percentage;
dispText =file.DisplayName;
}
}
}
tb.Text = dispText;
//.........这里部分代码省略.........
示例12: processImage
private async void processImage(int size)
{
if (Button1.Tag.ToString() == "0")
{
MessageDialog md = new MessageDialog("请先选择图片");
await md.ShowAsync();
}
else
{
try
{
StorageFile file = (StorageFile)Image1.Tag;
//WriteableBitmap image = (WriteableBitmap)Image1.Source;
BitmapImage image = new BitmapImage();
await image.SetSourceAsync(await file.OpenAsync(FileAccessMode.Read));
double proportion = Convert.ToDouble(image.PixelWidth) / Convert.ToDouble(image.PixelHeight);
int width = 360;
if (size == 0)
{
width = image.PixelWidth;
}
else if (size==1)
{
if (image.PixelWidth > 1024)
{
width = 1024;
}
else
{
width = image.PixelWidth/2;
}
}
else
{
width = 320;
}
int height = Convert.ToInt32(width / proportion);
WriteableBitmap wb = new WriteableBitmap(image.PixelWidth, image.PixelHeight);
await wb.SetSourceAsync(await file.OpenAsync(FileAccessMode.Read));
System.Diagnostics.Debug.WriteLine("wb:" + wb.PixelHeight);
WriteableBitmap newwb = wb.Resize(width, height, WriteableBitmapExtensions.Interpolation.NearestNeighbor);
Image1.Source = newwb;
uploadButton.Tag = "1";//可以上传了
// Image1.Source = wb;
}
catch (Exception exp)
{
System.Diagnostics.Debug.WriteLine(exp.Message);
}
}
}