本文整理汇总了C#中System.Drawing.Bitmap.LockBits方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Bitmap.LockBits方法的具体用法?C# System.Drawing.Bitmap.LockBits怎么用?C# System.Drawing.Bitmap.LockBits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Bitmap
的用法示例。
在下文中一共展示了System.Drawing.Bitmap.LockBits方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToBitmap
public System.Drawing.Bitmap ToBitmap()
{
#if WindowsCE
var bmp = new System.Drawing.Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
var bmpData = bmp.LockBits(
new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
System.Drawing.Imaging.ImageLockMode.WriteOnly,
System.Drawing.Imaging.PixelFormat.Format32bppRgb);
#else
var bmp = new System.Drawing.Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
bmp.SetResolution(96, 96);
var bmpData = bmp.LockBits(
new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
System.Drawing.Imaging.ImageLockMode.WriteOnly,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
#endif
try
{
//Copy the data from the byte array into BitmapData.Scan0
System.Runtime.InteropServices.Marshal.Copy(Pixels, 0, bmpData.Scan0, Pixels.Length);
}
finally
{
//Unlock the pixels
bmp.UnlockBits(bmpData);
}
return bmp;
}
示例2: GetVideoFrame
public static BitmapImage GetVideoFrame(string FileName, double Delta)
{
IntPtr Bits = IntPtr.Zero;
int Width = 0;
int Height = 0;
if (!GetVideoFrame(FileName, Delta, ref Bits, ref Width, ref Height))
{
throw new Exception("GetVideoFrame called failed");
}
var bmp = new System.Drawing.Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
var bmpData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadWrite,
System.Drawing.Imaging.PixelFormat.Format24bppRgb);
MoveMemory(bmpData.Scan0, Bits, bmpData.Stride * bmpData.Height);
bmp.UnlockBits(bmpData);
Marshal.FreeHGlobal(Bits);
var ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
var bmpImage = new BitmapImage();
bmpImage.BeginInit();
bmpImage.StreamSource = ms;
bmpImage.EndInit();
return bmpImage;
}
示例3: Copy
public System.Drawing.Bitmap Copy()
{
var bitmap = new System.Drawing.Bitmap(m_wicBitmap.Size.Width, m_wicBitmap.Size.Height);
System.Drawing.Imaging.BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
System.Drawing.Imaging.ImageLockMode.WriteOnly, bitmap.PixelFormat);
m_wicBitmap.CopyPixels(data.Stride, data.Scan0, data.Height * data.Stride);
bitmap.UnlockBits(data);
return bitmap;
}
示例4: MagickGetImageBitmap
/// <summary>
/// Gets a System.Drawing.Bitmap from an ImageMagick wand.
/// </summary>
/// <param name="wand"></param>
/// <returns></returns>
public static System.Drawing.Bitmap MagickGetImageBitmap(MagickWand wand)
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(
(int)MagickGetImageWidth(wand), (int)MagickGetImageHeight(wand));
System.Drawing.Imaging.BitmapData bmpdat = bmp.LockBits(
new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height),
System.Drawing.Imaging.ImageLockMode.ReadOnly,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
MagickExportImagePixels(wand, 0, 0, MagickGetImageWidth(wand), MagickGetImageHeight(wand),
"ARGB", StorageType.CharPixel, bmpdat.Scan0);
return bmp;
}
示例5: SkiaCanvasViewport
public SkiaCanvasViewport(RootGraphic rootgfx,
Size viewportSize, int cachedPageNum)
: base(rootgfx, viewportSize, cachedPageNum)
{
this.CalculateCanvasPages();
mySkCanvas = new PixelFarm.Drawing.Skia.MySkiaCanvas(0, 0, 0, 0, internalSizeW, internalSizwH);
//TODO: review performance here
//review how to move data from unmanged(skia) to unmanaged(hdc's bitmap)
tmpBmp = new System.Drawing.Bitmap(internalSizeW, internalSizwH);
var bmpdata = tmpBmp.LockBits(
new System.Drawing.Rectangle(0, 0, internalSizeW, internalSizwH),
System.Drawing.Imaging.ImageLockMode.ReadOnly, tmpBmp.PixelFormat);
tmpBuffer = new byte[bmpdata.Stride * bmpdata.Height];
tmpBmp.UnlockBits(bmpdata);
}
示例6: IndexedTexture
/** Load the image from file */
public IndexedTexture(String pathIn)
{
String path = pathIn.Replace('/', '\\');
try
{
//Load image
String extension = System.IO.Path.GetExtension(path);
if (!extension.Equals(".bmp", StringComparison.CurrentCultureIgnoreCase) &&
!extension.Equals(".png", StringComparison.CurrentCultureIgnoreCase))
throw new Exception("expected bmp or png image.");
System.Drawing.Bitmap img = new System.Drawing.Bitmap(path.Replace('/','\\'));
if(img.PixelFormat != System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
throw new Exception("Image must be indexed.");
//Get palette
palette = new Palette(img.Palette);
//Get indices
System.Drawing.Imaging.BitmapData data = img.LockBits(
new System.Drawing.Rectangle(0,0,img.Width, img.Height),
System.Drawing.Imaging.ImageLockMode.ReadOnly,
System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
//Upload
indexTexture = Gl.GenTexture();
Gl.BindTexture(TextureTarget.Texture2D, indexTexture);
Gl.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.R8,
data.Width, data.Height, 0, PixelFormat.Red, PixelType.UnsignedByte, data.Scan0);
Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, TextureParameter.Nearest);
Gl.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, TextureParameter.Nearest);
width = data.Width;
height = data.Height;
}
catch(Exception e)
{
throw new Exception(String.Format("Can not load \"{0}\": {1}", path, e.Message), e);
}
}
示例7: GenerateAlphaTexture
public static int GenerateAlphaTexture(byte[] values)
{
GL.ActiveTexture(TextureUnit.Texture1);
int textureId = GL.GenTexture();
var bmp = new System.Drawing.Bitmap(64, 64);
for (int x = 0; x < 64; x++)
{
for (int y = 0; y < 64; y++)
{
var color = System.Drawing.Color.FromArgb(values[x * 64 + y], values[x * 64 + y], values[x * 64 + y], values[x * 64 + y]);
bmp.SetPixel(x, y, color);
}
}
GL.BindTexture(TextureTarget.Texture2D, textureId);
System.Drawing.Imaging.BitmapData bmp_data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp_data.Width, bmp_data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp);
GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int) TextureEnvMode.Modulate);
bmp.UnlockBits(bmp_data);
// bmp.Save("alphatest_" + textureId + ".bmp");
GL.ActiveTexture(TextureUnit.Texture0);
return textureId;
}
示例8: Initialize
// --- functions ---
/// <summary>Initializes the screen. A call to SDL_Init must have been made before calling this function. A call to Deinitialize must be made when terminating the program.</summary>
/// <returns>Whether initializing the screen was successful.</returns>
internal static bool Initialize() {
if (SDL.SDL_InitSubSystem(SDL.SDL_INIT_VIDEO) != 0) {
return false;
}
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DOUBLEBUFFER, 1);
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_RED_SIZE, 8);
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_GREEN_SIZE, 8);
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_BLUE_SIZE, 8);
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_ALPHA_SIZE, 0);
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_DEPTH_SIZE, 24);
SDL.SDL_GL_SetSwapInterval(Options.Current.VerticalSynchronization ? 1 : 0);
if (Options.Current.AntiAliasingLevel != 0) {
SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_MULTISAMPLESAMPLES, Options.Current.AntiAliasingLevel);
}
// --- video mode ---
Width = Options.Current.FullscreenMode ? Options.Current.FullscreenWidth : Options.Current.WindowWidth;
Height = Options.Current.FullscreenMode ? Options.Current.FullscreenHeight : Options.Current.WindowHeight;
Fullscreen = Options.Current.FullscreenMode;
SDL.SDL_WindowFlags flags = SDL.SDL_WindowFlags.SDL_WINDOW_OPENGL/*| SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE*/
| SDL.SDL_WindowFlags.SDL_WINDOW_HIDDEN | SDL.SDL_WindowFlags.SDL_WINDOW_RESIZABLE;
if (Fullscreen) {
flags |= SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
}
SDL.SDL_SetHint(SDL.SDL_HINT_RENDER_VSYNC, "true");
SDL.SDL_SetHint(SDL.SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "false");
Window = SDL.SDL_CreateWindow(Application.ProductName, SDL.SDL_WINDOWPOS_CENTERED, SDL.SDL_WINDOWPOS_CENTERED, Width, Height, flags);
if (Window == IntPtr.Zero) {
// --- not successful ---
SDL.SDL_QuitSubSystem(SDL.SDL_INIT_VIDEO);
return false;
}
GLContext = SDL.SDL_GL_CreateContext(Window);
// --- set up OpenTK context
tkContext = new GraphicsContext(new ContextHandle(GLContext),
SDL.SDL_GL_GetProcAddress,
() => new ContextHandle(SDL.SDL_GL_GetCurrentContext()));
// --- set up icon ---
string bitmapFile = OpenBveApi.Path.CombineFile(Program.FileSystem.DataFolder, "icon.png");
if (System.IO.File.Exists(bitmapFile)) {
iconBmp = new System.Drawing.Bitmap(bitmapFile); // load file
iconData = iconBmp.LockBits(new System.Drawing.Rectangle(0, 0, iconBmp.Width, iconBmp.Height),
System.Drawing.Imaging.ImageLockMode.ReadOnly,
System.Drawing.Imaging.PixelFormat.Format32bppArgb); // lock data
iconSurface = SDL.SDL_CreateRGBSurfaceFrom(iconData.Scan0, iconBmp.Width, iconBmp.Height, 32, iconData.Stride,
0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000); // upload to sdl
SDL.SDL_SetWindowIcon(Window, iconSurface); // use icon
// free in Deinitialize()
}
// --- set up anisotropic filtering ---
Options.Current.AnisotropicFilteringMaximum = 0;
string[] extensions = GL.GetString(StringName.Extensions).Split(new []{ ' ' });
for (int i = 0; i < extensions.Length; i++) {
if (extensions[i] == "GL_EXT_texture_filter_anisotropic") {
float n;
GL.GetFloat((GetPName)ExtTextureFilterAnisotropic.MaxTextureMaxAnisotropyExt, out n);
int m = (int)Math.Round(n);
Options.Current.AnisotropicFilteringMaximum = Math.Max(0, m);
break;
}
}
if (Options.Current.AnisotropicFilteringLevel <= 0) {
Options.Current.AnisotropicFilteringLevel = Options.Current.AnisotropicFilteringMaximum;
} else if (Options.Current.AnisotropicFilteringLevel > Options.Current.AnisotropicFilteringMaximum) {
Options.Current.AnisotropicFilteringLevel = Options.Current.AnisotropicFilteringMaximum;
}
// --- done ---
Initialized = true;
return true;
}
示例9: Layer
public unsafe Layer(PSD.Layer layer)
{
this.layer = layer;
Name = layer.Name;
Rect = layer.Rect;
var wi = new System.Drawing.Bitmap(Rect.Width, Rect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
fixed (Color* p = layer.Pixels)
{
var acc = wi.LockBits(new System.Drawing.Rectangle(0, 0, wi.Width, wi.Height),
System.Drawing.Imaging.ImageLockMode.ReadWrite,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
for (int y = 0; y < Rect.Height; y++)
{
for (int x = 0; x < Rect.Width; x++)
{
var src = *(p + x + y * Rect.Width);
var dst = (Color*)acc.Scan0 + x + y * Rect.Width;
var r = src.R;
var b = src.B;
src.B = r;
src.R = b;
*dst = src;
}
}
wi.UnlockBits(acc);
}
Image = wi;
}
示例10: FromSysBMP
/// <summary>
/// Converts a <see cref="System.Drawing.Bitmap"/> object into a <see cref="SharpDX.Direct2D1.Bitmap"/> object for rendering.
/// </summary>
/// <param name="renderTarget">The <see cref="SharpDX.Direct2D1.RenderTarget"/> object that images are drawn on.</param>
/// <param name="bmp">The .NET native bitmap image.</param>
/// <returns>A <see cref="SharpDX.Direct2D1.Bitmap"/> containing the image data retrieved from the <see cref="System.Drawing.Bitmap"/> object.</returns>
public static Bitmap FromSysBMP(RenderTarget renderTarget, SystemBitmap bmp)
{
var imageArea = new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height);
var bmpProps = new BitmapProperties(new SharpDX.Direct2D1.PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Premultiplied));
// Unmanaged buffer needs proper disposal
using (var dataStream = new DataStream(bmp.ByteSize(), true, true))
{
var bmpData = bmp.LockBits(imageArea, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
for (int y = 0; y < bmp.Height; y++)
{
int offset = y * bmpData.Stride;
for (int x = 0; x < bmp.Width; x++)
{
// System bitmaps store pixel values as BGRA byte arrays
byte b = Marshal.ReadByte(bmpData.Scan0, offset++);
byte g = Marshal.ReadByte(bmpData.Scan0, offset++);
byte r = Marshal.ReadByte(bmpData.Scan0, offset++);
byte a = Marshal.ReadByte(bmpData.Scan0, offset++);
// Convert BGRA to RGBA (stored as a 32 bit = 4 byte integer)
int rgba = r | (g << 8) | (b << 16) | (a << 24);
// Write the RGBA value to the data buffer
dataStream.Write(rgba);
}
}
// Release the lock on the bitmap & reset the buffer position pointer
bmp.UnlockBits(bmpData);
dataStream.Position = 0;
return new Bitmap(renderTarget, new Size2(bmp.Width, bmp.Height), dataStream, bmpData.Stride, bmpProps);
}
}
示例11: InitColorRampFromImage
private static Color[] InitColorRampFromImage(String imageFile)
{
Color[] colorRamp = null;
try
{
System.Drawing.Bitmap bm = new System.Drawing.Bitmap(imageFile);
colorRamp = new Color[bm.Width];
System.Drawing.Rectangle r = new System.Drawing.Rectangle(0, 0, bm.Width, bm.Height);
BitmapData bitmapData = bm.LockBits(r, ImageLockMode.ReadOnly, bm.PixelFormat);
byte[] pixelData = new byte[bitmapData.Stride];
IntPtr pData = bitmapData.Scan0;
Marshal.Copy(pData, pixelData, 0, bitmapData.Stride);
for (int i = 0, rampPos = 0; i < bitmapData.Stride; i += 4, ++rampPos)
{
byte alpha = pixelData[i + 3];
byte red = pixelData[i + 2];
byte green = pixelData[i + 1];
byte blue = pixelData[i + 0];
colorRamp[rampPos] = Color.FromNonPremultiplied(red, green, blue, alpha);
}
bm.UnlockBits(bitmapData);
}
catch (Exception) {}
return colorRamp;
}
示例12: CaptureScreenshotAsyncHelper
//.........这里部分代码省略.........
cameraPixelsBuffer.GetData(cameraPixels);
if (cameraPixels[cameraPixelsBuffer.count - 1] != BufferSentinelValue)
ReportOutOfGraphicsMemory();
}
RenderTexture.active = null;
if (saveCubemap &&
!(captureStereoscopic && usingGpuTransform)) // In this mode images are saved during capture
{
// Save cubemap while still faded, as fast as possible - should be pretty quick
for (int i = 0; i < numCameras; i++)
{
int bufferIdx = i;
SaveCubemapImage(cameraPixels, filenameBase, suffix, imagePath, i, bufferIdx);
}
}
// If this is not here, the fade-in will drop frames.
for (int i = 0; i < 2; i++)
yield return new WaitForEndOfFrame();
if (async && !usingGpuTransform && fadeDuringCapture)
yield return StartCoroutine(FadeIn(fadeControls));
filePath = imagePath + "/" + filenameBase + suffix;
bool producedImageSuccess = false;
{
// Write pixels directly to .NET Bitmap for saving out
// Based on https://msdn.microsoft.com/en-us/library/5ey6h79d%28v=vs.110%29.aspx
Bitmap bitmap = new Bitmap(panoramaWidth, panoramaHeight * (captureStereoscopic ? 2 : 1), PixelFormat.Format32bppArgb);
var bmpData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, bitmap.PixelFormat);
IntPtr ptr = bmpData.Scan0;
byte[] pixelValues = new byte[Math.Abs(bmpData.Stride) * bitmap.Height];
// Convert to equirectangular projection - use compute shader for better performance if supported by platform
if (async)
yield return StartCoroutine(CubemapToEquirectangular(cameraPixelsBuffer, cameraPixels, convertPanoramaResultBuffer, cameraWidth, cameraHeight, pixelValues, bmpData.Stride, panoramaWidth, panoramaHeight, ssaaFactor, async));
else
{
var enumerator = CubemapToEquirectangular(cameraPixelsBuffer, cameraPixels, convertPanoramaResultBuffer, cameraWidth, cameraHeight, pixelValues, bmpData.Stride, panoramaWidth, panoramaHeight, ssaaFactor, async);
while (enumerator.MoveNext()) { }
}
producedImageSuccess = (pixelValues[3] == 255);
yield return null;
System.Runtime.InteropServices.Marshal.Copy(pixelValues, 0, ptr, pixelValues.Length);
bitmap.UnlockBits(bmpData);
yield return null;
Log("Time to take panorama screenshot: " + (Time.realtimeSinceStartup - startTime) + " sec");
if (producedImageSuccess)
{
var thread = new Thread(() =>
{
Log("Saving equirectangular image");
// TODO: Use better image processing library to get decent JPEG quality out.
bitmap.Save(filePath, FormatToDrawingFormat(imageFormat));
});
thread.Start();
while (thread.ThreadState == ThreadState.Running)
示例13: showDepthView
//, int p1, int p2)//, ThreeDAuth.DepthPoint hand)
/// <summary>
/// Siavash
/// </summary>
/// <param name="depthFrame"></param>
/// <param name="p1"></param>
/// <param name="p2"></param>
private void showDepthView(DepthImageFrame depthFrame, DrawingContext drawingContext)
{
bmap = new System.Drawing.Bitmap(depthFrame.Width, depthFrame.Height, System.Drawing.Imaging.PixelFormat.Format16bppRgb555);
System.Drawing.Imaging.BitmapData bmapdata = bmap.LockBits(new System.Drawing.Rectangle(0, 0, depthFrame.Width
, depthFrame.Height), ImageLockMode.WriteOnly, bmap.PixelFormat);
IntPtr ptr = bmapdata.Scan0;
Marshal.Copy(imadeData, 0, ptr, depthFrame.Width * depthFrame.Height);
bmap.UnlockBits(bmapdata);
/*System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmap);
this.myImageBox.Source =
System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
bmap.GetHbitmap(),
IntPtr.Zero,
System.Windows.Int32Rect.Empty,
BitmapSizeOptions.FromWidthAndHeight((int)this.myImageBox.Width, (int)this.myImageBox.Height));*/
ThreeDAuth.BoundingRectangle rect = ThreeDAuth.BoundingRectangle.CreateBoundingRectangle(myPointCluster);
using (DrawingContext lfdc = drawingContext )//this.liveFeedbackGroup.Open())
{
lfdc.DrawImage(System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
bmap.GetHbitmap(),
IntPtr.Zero,
System.Windows.Int32Rect.Empty,
BitmapSizeOptions.FromWidthAndHeight((int)this.myImageBox.Width, (int)this.myImageBox.Height)),
new Rect(0.0, 0.0, RenderWidth, RenderHeight));
foreach (DepthPoint point in myPointCluster.points)
{
lfdc.DrawRoundedRectangle(Brushes.Red, null, new Rect(point.x, point.y, 3, 3), null, 1, null, 1, null);
}
/*
if (userImage != null)
{
lfdc.DrawImage(userImage, new Rect(0.0, 0.0, RenderWidth, RenderHeight));
}
* */
//Console.WriteLine(myPointCluster.points.Count);
/*
foreach (ThreeDAuth.DepthPoint point in myPointCluster.points)
{
lfdc.DrawRoundedRectangle(Brushes.Red, null, new Rect(point.x, point.y, 3, 3), null, 1, null, 1, null);
}
int xPos = badPoint % depthFrame.Width;
int yPos = badPoint / depthFrame.Width;
lfdc.DrawRoundedRectangle(Brushes.Green, null, new Rect(xPos - 15, yPos - 15, 30, 30), null, 14, null, 14, null);
if (rightWrist.TrackingState == JointTrackingState.Tracked)
{
ThreeDAuth.DepthPoint right = this.SkeletonPointToScreen(rightWrist.Position);
lfdc.DrawRoundedRectangle(Brushes.Gold, null, new Rect(right.x - 15, right.y - 15, 30, 30), null, 14, null, 14, null);
}
*/
//lfdc.DrawRoundedRectangle(Brushes.Blue, null, new Rect(hand.x - 15, hand.y - 15, 30, 30), null, 14, null, 14, null);
//ThreeDAuth.PointDistributor.SGivePoint(hand);
}
}
示例14: ApplyOverlay
public System.Drawing.Bitmap ApplyOverlay(HeightData heights, System.Drawing.Bitmap overlayBitmap)
{
// prepare byte access to the overlay bitmap
System.Drawing.Rectangle OverlayRect = new System.Drawing.Rectangle(0, 0, overlayBitmap.Width, overlayBitmap.Height);
System.Drawing.Imaging.BitmapData overlayData = overlayBitmap.LockBits(OverlayRect, System.Drawing.Imaging.ImageLockMode.ReadOnly, overlayBitmap.PixelFormat);
// create a blank bitmap and prepare it for byte access
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(heights.Width, heights.Height, overlayData.PixelFormat);
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height);
System.Drawing.Imaging.BitmapData data = bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, overlayBitmap.PixelFormat);
// prepare memory space for the newly created color data
byte[] bytes = new byte[data.Stride * bitmap.Height];
byte[] overlayCopy = new byte[overlayData.Stride * overlayBitmap.Height];
int pixelSize = overlayData.Stride / overlayBitmap.Width;
// get a pointer to the to first line (=first pixel)
IntPtr ptr = data.Scan0;
IntPtr overlayPtr = overlayData.Scan0;
// create a byte copy of the heightmap data
System.Runtime.InteropServices.Marshal.Copy(overlayPtr, overlayCopy, 0, overlayData.Stride * overlayBitmap.Height);
// create the color data
// standard format overlay (positive values only)
if (overlayBitmap.Width == 256)
{
for (int y = 0; y < heights.Height; y++)
{
for (int x = 0; x < heights.Width; x++)
{
int index = y * data.Stride + x * pixelSize;
int current = (heights[x + y * heights.Width] / 128);
if (current < 0) current = 0;
// prevent water bleeding onto the coastline
if (heights[x + y * heights.Width] > 0 && current == 0) current = 1;
for (int channelIndex = 0; channelIndex < pixelSize; channelIndex++)
{
bytes[index + channelIndex] = overlayCopy[current * pixelSize + channelIndex];
}
}
}
}
// extended overlay (positive AND negative values)
else
{
for (int y = 0; y < heights.Height; y++)
{
for(int x = 0; x < heights.Width; x++)
{
int index = y * data.Stride + x * pixelSize;
int current = 255 + (heights[x + y * heights.Width] / 128);
if (current < 0 || current > 511)
{
throw new Exception("This cannot happen");
}
// prevent water bleeding onto the coastline
if (current == 255 && heights[x + y * heights.Width] > 0) current = 256;
for (int channelIndex = 0; channelIndex < pixelSize; channelIndex++)
{
bytes[index + channelIndex] = overlayCopy[current * pixelSize + channelIndex];
}
}
}
}
// copy the data into the bitmap
System.Runtime.InteropServices.Marshal.Copy(bytes, 0, ptr, data.Stride * bitmap.Height);
// unlock the bits
bitmap.UnlockBits(data);
return bitmap;
}
示例15: SaveImage
public override void SaveImage(System.IO.Stream iso, System.IO.Stream output)
{
List<List<byte>> quadrantBytes = new List<List<byte>>();
for (int i = 0; i < 4; i++)
{
quadrantBytes.Add(new List<byte>());
foreach (PatcherLib.Iso.PsxIso.KnownPosition pos in isoPositions[i])
{
quadrantBytes[i].AddRange(pos.ReadIso(iso));
}
}
List<byte> totalBytes = new List<byte>();
for (int rowIndex = 0; rowIndex < 240; rowIndex++)
{
int byteIndex0 = rowIndex * 240;
int byteIndex1 = rowIndex * 256;
totalBytes.AddRange(quadrantBytes[0].Sub(byteIndex0, byteIndex0 + 239));
totalBytes.AddRange(quadrantBytes[1].Sub(byteIndex1, byteIndex1 + 255));
}
for (int rowIndex = 0; rowIndex < 128; rowIndex++)
{
int byteIndex2 = rowIndex * 240;
int byteIndex3 = rowIndex * 256;
totalBytes.AddRange(quadrantBytes[2].Sub(byteIndex2, byteIndex2 + 239));
totalBytes.AddRange(quadrantBytes[3].Sub(byteIndex3, byteIndex3 + 255));
}
byte[] imageBytes = totalBytes.ToArray();
// Get colors
Palette p = new Palette(palettePositions[0].ReadIso(iso), FFTPatcher.SpriteEditor.Palette.ColorDepth._16bit, true);
// Convert colors to indices
System.Drawing.Bitmap originalImage = GetImageFromIso(iso);
using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(Width, Height, System.Drawing.Imaging.PixelFormat.Format8bppIndexed))
{
System.Drawing.Imaging.ColorPalette pal = bmp.Palette;
for (int i = 0; i < p.Colors.Length; i++)
{
pal.Entries[i] = p.Colors[i];
}
bmp.Palette = pal;
var bmd = bmp.LockBits(new System.Drawing.Rectangle(0, 0, Width, Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
for (int y = 0; y < Height; y++)
{
for (int x = 0; x < Width; x++)
{
bmd.SetPixel8bpp(x, y, imageBytes[(y * Width) + x]);
}
}
bmp.UnlockBits(bmd);
// Write that shit
//bmp.Save( output, System.Drawing.Imaging.ImageFormat.Gif );
bmp.Save(output, System.Drawing.Imaging.ImageFormat.Bmp);
}
}