本文整理汇总了C#中System.Windows.Media.Imaging.WriteableBitmap.SetPixel方法的典型用法代码示例。如果您正苦于以下问题:C# WriteableBitmap.SetPixel方法的具体用法?C# WriteableBitmap.SetPixel怎么用?C# WriteableBitmap.SetPixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.Imaging.WriteableBitmap
的用法示例。
在下文中一共展示了WriteableBitmap.SetPixel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CharacterBitmap
public CharacterBitmap(byte[] data)
{
//Load the data into the byte array
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 8; j++)
{
Character[j] = data[i];
i++;
}
}
//Now generate a bitmap somehow
CharacterImage = new WriteableBitmap(8, 8, 96, 96, PixelFormats.Bgr32, null);
CharacterImage.Lock();
for(int i = 0; i < 8; i++)
{
if((Character[i] & 0x10) == 0x10)
{
CharacterImage.SetPixel(3, i, Colors.White);
} else
{
CharacterImage.SetPixel(3, i, Colors.Black);
}
if ((Character[i] & 0x08) == 0x08)
{
CharacterImage.SetPixel(4, i, Colors.White);
}
else
{
CharacterImage.SetPixel(4, i, Colors.Black);
}
if ((Character[i] & 0x04) == 0x04)
{
CharacterImage.SetPixel(5, i, Colors.White);
}
else
{
CharacterImage.SetPixel(5, i, Colors.Black);
}
if ((Character[i] & 0x02) == 0x02)
{
CharacterImage.SetPixel(6, i, Colors.White);
}
else
{
CharacterImage.SetPixel(6, i, Colors.Black);
}
if ((Character[i] & 0x01) == 0x01)
{
CharacterImage.SetPixel(7, i, Colors.White);
}
else
{
CharacterImage.SetPixel(7, i, Colors.Black);
}
}
CharacterImage.Unlock();
}
示例2: PreviewImage_OnLoaded
private void PreviewImage_OnLoaded(object sender, RoutedEventArgs e)
{
_bitmap = BitmapFactory.New(500, 500);
for (var y = 0; y < 500; ++y)
{
for (var x1 = 0; x1 < 250; ++x1)
{
_bitmap.SetPixel(x1,y,WriteableBitmapExtensions.ConvertColor(Colors.DodgerBlue));
_bitmap.SetPixel(x1+250, y, WriteableBitmapExtensions.ConvertColor(Colors.SeaGreen));
}
}
_bitmap.FillEllipseCentered(225, 225, 50, 50, WriteableBitmapExtensions.ConvertColor(0.5, Colors.Red), true);
//_bitmap.FillRectangle(200, 200, 250, 250, WriteableBitmapExtensions.ConvertColor(0.5, Colors.Red), true);
PreviewImage.Source = _bitmap;
}
示例3: BaseTool
protected BaseTool(WorldViewModel worldViewModel)
{
_wvm = worldViewModel;
_preview = new WriteableBitmap(1, 1, 96, 96, PixelFormats.Bgra32, null);
_preview.Clear();
_preview.SetPixel(0, 0, 127, 0, 90, 255);
}
示例4: SelectionTool
public SelectionTool(WorldViewModel worldViewModel)
{
_wvm = worldViewModel;
_preview = new WriteableBitmap(1, 1, 96, 96, PixelFormats.Bgra32, null);
_preview.Clear();
_preview.SetPixel(0, 0, 127, 0, 90, 255);
Icon = new BitmapImage(new Uri(@"pack://application:,,,/TEditXna;component/Images/Tools/shape_square.png"));
Name = "Selection";
IsActive = false;
}
示例5: ToBitmapImageAsync
public static async Task<WriteableBitmap> ToBitmapImageAsync(this BitmapHolder holder)
{
if (holder == null || holder.Pixels == null)
return null;
WriteableBitmap writeableBitmap = null;
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
{
writeableBitmap = new WriteableBitmap(holder.Width, holder.Height);
for (int x = 0; x < holder.Width; x++)
for (int y = 0; y < holder.Height; y++)
writeableBitmap.SetPixel(x, y, holder.Pixels[x + y * holder.Width]);
writeableBitmap.Invalidate();
});
return writeableBitmap;
}
示例6: captureSnapshot
private static async void captureSnapshot(ushort[] pixeldata, int pitch, string filename)
{
WriteableBitmap bitmap = new WriteableBitmap(pitch / 2, (int)pixeldata.Length / (pitch / 2));
int x = 0;
int y = 0;
for (int i = 0; i < bitmap.PixelWidth * bitmap.PixelHeight; i++)
{
ushort pixel = pixeldata[i];
byte r = (byte)((pixel & 0xf800) >> 11);
byte g = (byte)((pixel & 0x07e0) >> 5);
byte b = (byte)(pixel & 0x001f);
r = (byte)((255 * r) / 31);
g = (byte)((255 * g) / 63);
b = (byte)((255 * b) / 31);
bitmap.SetPixel(x, y, r, g, b);
x++;
if (x >= bitmap.PixelWidth)
{
y++;
x = 0;
}
}
String snapshotName = filename.Substring(0, filename.Length - 3) + "jpg";
//StorageFolder folder = await ApplicationData.Current.LocalFolder.GetFolderAsync(ROM_DIRECTORY);
////StorageFolder saveFolder = await folder.GetFolderAsync(SAVE_DIRECTORY);
//StorageFolder shared = await folder.GetFolderAsync("Shared");
//StorageFolder shellContent = await shared.GetFolderAsync("ShellContent");
//StorageFile file = await shellContent.CreateFileAsync(snapshotName, CreationCollisionOption.ReplaceExisting);
try
{
IsolatedStorageFile iso = IsolatedStorageFile.GetUserStoreForApplication();
using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream("/Shared/ShellContent/" + snapshotName, System.IO.FileMode.Create, iso))
{
bitmap.SaveJpeg(fs, bitmap.PixelWidth, bitmap.PixelHeight, 0, 90);
//await fs.FlushAsync();
fs.Flush(true);
}
ROMDatabase db = ROMDatabase.Current;
ROMDBEntry entry = db.GetROM(filename);
entry.SnapshotURI = "Shared/ShellContent/" + snapshotName;
db.CommitChanges();
UpdateLiveTile();
UpdateROMTile(filename);
}
catch (Exception)
{
}
//try
//{
// using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
// using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
// {
// bitmap.SaveJpeg(ms, bitmap.PixelWidth, bitmap.PixelHeight, 0, 90);
// byte[] bytes = ms.ToArray();
// DataWriter writer = new DataWriter(stream);
// writer.WriteBytes(bytes);
// await writer.StoreAsync();
// writer.DetachStream();
// await stream.FlushAsync();
// }
// ROMDatabase db = ROMDatabase.Current;
// ROMDBEntry entry = db.GetROM(filename);
// entry.SnapshotURI = "Shared/ShellContent/" + snapshotName;
// db.CommitChanges();
//}
//catch (Exception e)
//{
// MessageBox.Show(e.Message);
//}
//await file.CopyAsync(shellContent);
}
示例7: Init
public void Init(Syscalls syscalls, Core core, Runtime runtime)
{
PhoneApplicationFrame frame = (PhoneApplicationFrame)Application.Current.RootVisual;
double screenWidth = System.Windows.Application.Current.Host.Content.ActualWidth;
double screenHeight = System.Windows.Application.Current.Host.Content.ActualHeight;
if ((int)screenHeight == 0)
throw new Exception("screenHeight");
PhoneApplicationPage mainPage = (PhoneApplicationPage)frame.Content;
mMainImage = new Image();
mainPage.Width = screenWidth;
mainPage.Height = screenHeight;
mMainImage.Width = screenWidth;
mMainImage.Height = screenHeight;
mainPage.Content = mMainImage;
mClipRect.X = 0.0;
mClipRect.Y = 0.0;
mClipRect.Width = screenWidth;
mClipRect.Height = screenHeight;
// no apparent effect on memory leaks.
runtime.RegisterCleaner(delegate()
{
MoSync.Util.RunActionOnMainThreadSync(() =>
{
mainPage.Content = null;
});
});
mBackBuffer = new WriteableBitmap(
(int)screenWidth,
(int)screenHeight);
mFrontBuffer = new WriteableBitmap(
(int)screenWidth,
(int)screenHeight);
mMainImage.Source = mFrontBuffer;
// clear front and backbuffer.
for (int i = 0; i < mFrontBuffer.PixelWidth * mFrontBuffer.PixelHeight; i++)
{
mBackBuffer.Pixels[i] = mBackBuffer.Pixels[i] = (int)(0xff<<24);
}
mCurrentDrawTarget = mBackBuffer;
mCurrentWindowsColor = System.Windows.Media.Color.FromArgb(0xff,
(byte)(mCurrentColor >> 16),
(byte)(mCurrentColor >> 8),
(byte)(mCurrentColor));
syscalls.maSetColor = delegate(int rgb)
{
int oldColor = (int)mCurrentColor;
mCurrentColor = 0xff000000 | (uint)(rgb & 0xffffff);
mCurrentWindowsColor = System.Windows.Media.Color.FromArgb(0xff,
(byte)(mCurrentColor >> 16),
(byte)(mCurrentColor >> 8),
(byte)(mCurrentColor));
return oldColor & 0xffffff;
};
syscalls.maSetClipRect = delegate(int x, int y, int w, int h)
{
MoSync.GraphicsUtil.ClipRectangle(
x, y, w, h,
0, 0, mCurrentDrawTarget.PixelWidth, mCurrentDrawTarget.PixelHeight,
out x, out y, out w, out h);
mClipRect.X = x;
mClipRect.Y = y;
mClipRect.Width = w;
mClipRect.Height = h;
};
syscalls.maGetClipRect = delegate(int cliprect)
{
Memory mem = core.GetDataMemory();
mem.WriteInt32(cliprect + MoSync.Struct.MARect.left, (int)mClipRect.X);
mem.WriteInt32(cliprect + MoSync.Struct.MARect.top, (int)mClipRect.Y);
mem.WriteInt32(cliprect + MoSync.Struct.MARect.width, (int)mClipRect.Width);
mem.WriteInt32(cliprect + MoSync.Struct.MARect.height, (int)mClipRect.Height);
};
syscalls.maPlot = delegate(int x, int y)
{
mCurrentDrawTarget.SetPixel(x, y, (int)mCurrentColor);
};
syscalls.maUpdateScreen = delegate()
{
//System.Array.Copy(mBackBuffer.Pixels, mFrontBuffer.Pixels, mFrontBuffer.PixelWidth * mFrontBuffer.PixelHeight);
System.Buffer.BlockCopy(mBackBuffer.Pixels, 0, mFrontBuffer.Pixels, 0, mFrontBuffer.PixelWidth * mFrontBuffer.PixelHeight * 4);
InvalidateWriteableBitmapOnMainThread(mFrontBuffer);
};
syscalls.maFillRect = delegate(int x, int y, int w, int h)
{
// this function has a bug (it only fills one pixel less than the image.)
//.........这里部分代码省略.........
示例8: ToGrayScale
/// <summary>
/// Converts a WritableBitmap to grayscale image
/// </summary>
public static WriteableBitmap ToGrayScale(WriteableBitmap bmp)
{
for (int i = 0; i < bmp.PixelHeight; i++)
{
for (int j = 0; j < bmp.PixelWidth; j++)
{
byte grayScale = Convert.ToByte((bmp.GetPixel(j, i).R * 0.3) + (bmp.GetPixel(j, i).G * 0.59) + (bmp.GetPixel(j, i).B * 0.11));
Color c = Color.FromArgb(255, grayScale, grayScale, grayScale);
bmp.SetPixel(j, i, c);
}
}
return bmp;
}
示例9: btnOpen_Click
private void btnOpen_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "JPEG,PNG,BMPファイル (*.jpg,*.png,*.bmp)|*.jpg;*.png;*.bmp";
ofd.Multiselect = false;
if (ofd.ShowDialog() != true) return;
string fn = ofd.File.Name.ToLower();
IImageDecoder dec;
if (fn.EndsWith(".jpg"))
{
dec = new JpegDecoder();
}
else if (fn.EndsWith(".png"))
{
dec = new PngDecoder();
}
else if (fn.EndsWith(".bmp"))
{
dec = new BmpDecoder();
}
else
{
MessageBox.Show("エラー");
return;
}
try
{
FileStream fs = ofd.File.OpenRead();
ImageTools.Image img = new ImageTools.Image();
dec.Decode(img, fs);
if (img.Width < 50 || img.Height < 50)
{
MessageBox.Show("画像サイズが小さすぎます");
return;
}
WriteableBitmap wb = new WriteableBitmap(img.Width, img.Height);
byte[] data = img.GetPixels();
for (int y = 0; y < img.Height; y++)
{
for (int x = 0; x < img.Width; x++)
{
int idx = (x + y * img.Width) * 4;
wb.SetPixel(x, y, Color.FromArgb(data[idx + 3], data[idx], data[idx + 1], data[idx + 2]));
}
}
SetImage(wb);
fs.Close();
}
catch
{
MessageBox.Show("エラー");
}
}
示例10: Render
public void Render(List<Vector2> stars, Color color, int size, WriteableBitmap screen)
{
if (size <= 1)
{
foreach (var star in stars)
{
// TODO: Outside bounds of array error can occur here! Float accuracy adding up?
screen.SetPixel((int)star.X, (int)star.Y, color);
}
}
else
{
foreach (var star in stars)
{
screen.FillRectangleFixed((int)star.X, (int)star.Y, (int)star.X + size, (int)star.Y + size, color);
}
}
}
示例11: PreviewTool
public override WriteableBitmap PreviewTool()
{
var bmp = new WriteableBitmap(
1,
1,
96,
96,
PixelFormats.Bgra32,
null);
bmp.Clear();
bmp.SetPixel(0, 0, 127, 0, 90, 255);
return bmp;
}
示例12: SaveFalseColor
public void SaveFalseColor(string filename)
{
var wbmp = new WriteableBitmap(Size.X, Size.Y, 96, 96, PixelFormats.Bgra32, null);
for (int y = 0; y < Size.Y; y++)
{
for (int x = 0; x < Size.X; x++)
{
var curtile = Tiles[x, y];
byte a = TileArgsToByte(curtile);
byte r = curtile.Type;
byte g = curtile.Wall;
byte b = curtile.Liquid;
wbmp.SetPixel(x, y, a, r, g, b);
}
}
wbmp.SavePng(filename);
}
示例13: RenderBuffer
public void RenderBuffer()
{
double scale = Math.Max((double)Size.X / ClipboardRenderSize, (double)Size.Y / ClipboardRenderSize);
int previewX = this.Size.X;
int previewY = this.Size.Y;
if (scale > 1.0)
{
previewX = (int)MathHelper.Clamp((float)Math.Min(ClipboardRenderSize, this.Size.X / scale), 1, ClipboardRenderSize);
previewY = (int)MathHelper.Clamp((float)Math.Min(ClipboardRenderSize, this.Size.Y / scale), 1, ClipboardRenderSize);
}
else
scale = 1;
var bmp = new WriteableBitmap(previewX, previewY, 96, 96, PixelFormats.Bgra32, null);
for (int x = 0; x < previewX; x++)
{
int tileX = (int)MathHelper.Clamp((float)(scale * x), 0, this.Size.X - 1);
for (int y = 0; y < previewY; y++)
{
int tileY = (int)MathHelper.Clamp((float)(scale * y), 0, this.Size.Y - 1);
var color = Render.PixelMap.GetTileColor(Tiles[tileX, tileY], Microsoft.Xna.Framework.Color.Transparent);
bmp.SetPixel(x, y, color.A, color.R, color.G, color.B);
}
}
Preview = bmp;
RenderScale = scale;
}
示例14: DrawGrid
private void DrawGrid(WriteableBitmap writeableBitmap)
{
Color color = Colors.White;
color.A = 50;
switch (GridType)
{
case 1:
{
for (int i = 1; i < 3; i++)
{
writeableBitmap.DrawLine(0, (int) ((writeableBitmap.Height/3)*i),
(int) writeableBitmap.Width,
(int) ((writeableBitmap.Height/3)*i), color);
writeableBitmap.DrawLine((int) ((writeableBitmap.Width/3)*i), 0,
(int) ((writeableBitmap.Width/3)*i),
(int) writeableBitmap.Height, color);
}
writeableBitmap.SetPixel((int) (writeableBitmap.Width/2), (int) (writeableBitmap.Height/2), 128,
Colors.Red);
}
break;
case 2:
{
for (int i = 1; i < 10; i++)
{
writeableBitmap.DrawLine(0, (int) ((writeableBitmap.Height/10)*i),
(int) writeableBitmap.Width,
(int) ((writeableBitmap.Height/10)*i), color);
writeableBitmap.DrawLine((int) ((writeableBitmap.Width/10)*i), 0,
(int) ((writeableBitmap.Width/10)*i),
(int) writeableBitmap.Height, color);
}
writeableBitmap.SetPixel((int) (writeableBitmap.Width/2), (int) (writeableBitmap.Height/2), 128,
Colors.Red);
}
break;
case 3:
{
writeableBitmap.DrawLineDDA(0, 0, (int) writeableBitmap.Width,
(int) writeableBitmap.Height, color);
writeableBitmap.DrawLineDDA(0, (int) writeableBitmap.Height,
(int) writeableBitmap.Width, 0, color);
writeableBitmap.SetPixel((int) (writeableBitmap.Width/2), (int) (writeableBitmap.Height/2), 128,
Colors.Red);
}
break;
case 4:
{
writeableBitmap.DrawLineDDA(0, (int) (writeableBitmap.Height/2), (int) writeableBitmap.Width,
(int) (writeableBitmap.Height/2), color);
writeableBitmap.DrawLineDDA((int) (writeableBitmap.Width/2), 0,
(int) (writeableBitmap.Width/2), (int) writeableBitmap.Height, color);
writeableBitmap.SetPixel((int) (writeableBitmap.Width/2), (int) (writeableBitmap.Height/2), 128,
Colors.Red);
}
break;
default:
try
{
if (GridType > 4)
{
string filename = Path.Combine(ServiceProvider.Settings.OverlayFolder,
SelectedOverlay + ".png");
if (File.Exists(filename))
{
BitmapImage bitmapSource = new BitmapImage();
bitmapSource.BeginInit();
bitmapSource.UriSource = new Uri(filename);
bitmapSource.EndInit();
WriteableBitmap overlay = BitmapFactory.ConvertToPbgra32Format(bitmapSource);
writeableBitmap.Blit(
new Rect(0, 0, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight),
overlay,
new Rect(0, 0, overlay.PixelWidth, overlay.PixelHeight));
}
}
}
catch (Exception)
{
}
break;
}
}
示例15: RenderBuffer
public void RenderBuffer()
{
var bmp = new WriteableBitmap(Size.X, Size.Y, 96, 96, PixelFormats.Bgra32, null);
for (int x = 0; x < Size.X; x++)
{
for (int y = 0; y < Size.Y; y++)
{
var color = Render.PixelMap.GetTileColor(Tiles[x, y], Microsoft.Xna.Framework.Color.Transparent);
bmp.SetPixel(x, y, color.A, color.R, color.G, color.B);
}
}
Preview = bmp;
}