本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap.ForEach方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.ForEach方法的具体用法?C# WriteableBitmap.ForEach怎么用?C# WriteableBitmap.ForEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.WriteableBitmap
的用法示例。
在下文中一共展示了WriteableBitmap.ForEach方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SavePhoto
public void SavePhoto()
{
var writeableBitmap = new WriteableBitmap(picture);
resizedOverlay = OverlayedPicture.Resize(writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, WriteableBitmapExtensions.Interpolation.Bilinear);
writeableBitmap.ForEach(Fill);
// Create a virtual store and file stream. Check for duplicate tempJPEG files.
string tempJPEG = CreateFileName();
var myStore = IsolatedStorageFile.GetUserStoreForApplication();
if (myStore.FileExists(tempJPEG)){
myStore.DeleteFile(tempJPEG);
}
IsolatedStorageFileStream myFileStream = myStore.CreateFile(tempJPEG);
writeableBitmap.SaveJpeg(myFileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, 85);
myFileStream.Close();
// Create a new stream from isolated storage, and save the JPEG file to the media library on Windows Phone.
myFileStream = myStore.OpenFile(tempJPEG, FileMode.Open, FileAccess.Read);
string fileName = CreateFileName();
new MediaLibrary().SavePictureToCameraRoll(fileName, myFileStream);
}
示例2: AdvGamePage
public AdvGamePage()
{
InitializeComponent();
var fileStream1 = Application.GetResourceStream(new Uri("TestImages/TestingUpper.png", UriKind.Relative));
var s1 = new BitmapImage();
using (var stream = fileStream1.Stream)
{
s1.SetSource(stream);
}
var upper = new WriteableBitmap(s1);
var fileStream2 = Application.GetResourceStream(new Uri("TestImages/TestingLower.png", UriKind.Relative));
var s2 = new BitmapImage();
using (var stream = fileStream2.Stream)
{
s2.SetSource(stream);
}
var lower = new WriteableBitmap(s2);
var upperEx = upper.GetBitmapContext();
var lowerEx = lower.GetBitmapContext();
UpperImage.Source = upper;
LowerImage.Source = lower;
upper.ForEach((x, y, color) =>
{
var lowerColor = lower.GetPixel(x, y);
return new Color
{
R = (byte) (color.R - lowerColor.R),
G = (byte) (color.G - lowerColor.G),
B = (byte) (color.B - lowerColor.B),
A = color.A
};
});
upper.Invalidate();
var changesPixels = new List<Point>();
upper.ForEach((x, y, color) =>
{
if (upper.GetPixel(x, y).R != 0)
{
lower.FillEllipseCentered(x, y, 10, 10, Colors.Red);
changesPixels.Add(new Point(x, y));
}
return color;
});
lower.Invalidate();
//var indicator = new bool[480, 320];
var startingPoint = changesPixels[0];
var newPointToBeInvestigate = new List<Point> { startingPoint };
changesPixels.Remove(startingPoint);
//indicator[(int)startingPoint.X, (int)startingPoint.Y] = true;
System.Diagnostics.Debug.WriteLine(DateTime.Now);
var i = 0;
while (newPointToBeInvestigate.Count > 0 && i < newPointToBeInvestigate.Count)
{
var newPixels = changesPixels.Where(p => DistanceBetweenPoints(newPointToBeInvestigate[i], p)).ToList();
foreach (var np in newPixels)
{
changesPixels.Remove(np);
newPointToBeInvestigate.Add(np);
}
//foreach (var newP in newPixels.Where(newP => !indicator[(int)newP.X, (int)newP.Y]))
//{
// indicator[(int)newP.X, (int)newP.Y] = true;
//}
i++;
}
System.Diagnostics.Debug.WriteLine(DateTime.Now);
foreach (var changeP in newPointToBeInvestigate)
{
lower.SetPixel((int)changeP.X, (int)changeP.Y, Colors.Green);
}
lower.Invalidate();
}