当前位置: 首页>>代码示例>>C#>>正文


C# System.Drawing.Bitmap.UnlockBits方法代码示例

本文整理汇总了C#中System.Drawing.Bitmap.UnlockBits方法的典型用法代码示例。如果您正苦于以下问题:C# System.Drawing.Bitmap.UnlockBits方法的具体用法?C# System.Drawing.Bitmap.UnlockBits怎么用?C# System.Drawing.Bitmap.UnlockBits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Drawing.Bitmap的用法示例。


在下文中一共展示了System.Drawing.Bitmap.UnlockBits方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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;
        }
开发者ID:vhanla,项目名称:XWindows-Dock-2.0,代码行数:29,代码来源:Video.cs

示例2: 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;
        }
开发者ID:Eagle-Chan,项目名称:KIS,代码行数:29,代码来源:PixelData.cs

示例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;
 }
开发者ID:Gfour84,项目名称:ATF,代码行数:9,代码来源:D2dWicGraphics.cs

示例4: 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);
        }
开发者ID:prepare,项目名称:HTML-Renderer,代码行数:16,代码来源:2_SkiaCanvasViewport.cs

示例5: 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;
        }
开发者ID:Ser0ja,项目名称:WoWFormatTest,代码行数:37,代码来源:BLPLoader.cs

示例6: GetBitmap

				public System.Drawing.Bitmap GetBitmap(Stream dataStream, bool bits8)
				{
					BinaryReader rdr = new BinaryReader(dataStream);
					int index = 0;
					System.Drawing.Bitmap img;
					byte[] data;
					if (bits8 == true)
					{
						switch (type)
						{
							case Types.Floor:
								data = rdr.ReadBytes((int)Length);
								img = new System.Drawing.Bitmap(46, 46);
                                System.Drawing.Imaging.BitmapData bitData = img.LockBits(new System.Drawing.Rectangle(0, 0, 46, 46), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                                IntPtr dataPtr = bitData.Scan0;
                                int[] bitmap = new int[46 * 46];
								int i = 1;
								int c = 23;
								for (int row = 0; index < data.Length && row < img.Width; row++)
								{
                                    for (int col = 0; index < data.Length && col < i; col++)
                                        bitmap[(col + c) + row * 46] = (int)(VideoBag.Palette[data[index++]]);
									if (row < 22)
									{
										i += 2;
										c--;
									}
									else if (row > 22)
									{
										i -= 2;
										c++;
									}
								}
                                System.Runtime.InteropServices.Marshal.Copy(bitmap, 0, dataPtr, 46 * 46);
                                img.UnlockBits(bitData);
								return img;
							case Types.Type3:
								int imgwidth = rdr.ReadInt32();
								int imgheight = rdr.ReadInt32();
								img = new System.Drawing.Bitmap(imgwidth, imgheight);
								rdr.ReadInt32();
								rdr.ReadInt32();
								byte b = 1;
								index = 0;
								int len = 0;
								while(b != 0 && rdr.BaseStream.Position < rdr.BaseStream.Length)
								{
									b = rdr.ReadByte();
									switch(b)
									{
										case 0:
											break;
										case 1:
											index += rdr.ReadByte();
											break;
										case 2:
											len = rdr.ReadByte();
											data = rdr.ReadBytes(len);
											for(int j = 0; j < len; j++)
												img.SetPixel(index%imgwidth,index-((index%imgwidth)*imgwidth),System.Drawing.Color.FromArgb((int)(VideoBag.Palette[data[j]])));
											break;
										default:
											Debug.WriteLine(String.Format("{0}: {1}",rdr.BaseStream.Position,b));
											break;
									}
								}
								break;
						}
					}
					return null;
				}
开发者ID:2asoft,项目名称:NoxMapEditor,代码行数:71,代码来源:VideoBag.cs

示例7: ExportBitmap

        /// <summary>
        /// Create a byte array containing 32-bit RGBA data with a bottom-left
        /// origin, suitable for feeding directly into OpenGL
        /// </summary>
        /// <returns>A byte array containing raw texture data</returns>
        public System.Drawing.Bitmap ExportBitmap()
        {
            byte[] raw = new byte[Width * Height * 4];

            if ((Channels & ImageChannels.Alpha) != 0)
            {
                if ((Channels & ImageChannels.Color) != 0)
                {
                    // RGBA
                    for (int pos = 0; pos < Height * Width; pos++)
                    {
                        raw[pos * 4 + 0] = Blue[pos];
                        raw[pos * 4 + 1] = Green[pos];
                        raw[pos * 4 + 2] = Red[pos];
                        raw[pos * 4 + 3] = Alpha[pos];
                    }
                }
                else
                {
                    // Alpha only
                    for (int pos = 0; pos < Height * Width; pos++)
                    {
                        raw[pos * 4 + 0] = Alpha[pos];
                        raw[pos * 4 + 1] = Alpha[pos];
                        raw[pos * 4 + 2] = Alpha[pos];
                        raw[pos * 4 + 3] = Byte.MaxValue;
                    }
                }
            }
            else
            {
                // RGB
                for (int pos = 0; pos < Height * Width; pos++)
                {
                    raw[pos * 4 + 0] = Blue[pos];
                    raw[pos * 4 + 1] = Green[pos];
                    raw[pos * 4 + 2] = Red[pos];
                    raw[pos * 4 + 3] = Byte.MaxValue;
                }
            }

            System.Drawing.Bitmap b = new System.Drawing.Bitmap(
                        Width,
                        Height,
                        System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            System.Drawing.Imaging.BitmapData bd = b.LockBits(new System.Drawing.Rectangle(0, 0, b.Width, b.Height),
                System.Drawing.Imaging.ImageLockMode.WriteOnly,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            System.Runtime.InteropServices.Marshal.Copy(raw, 0, bd.Scan0, Width * Height * 4);

            b.UnlockBits(bd);

            return b;
        }
开发者ID:KSLcom,项目名称:Aurora-LibOMV,代码行数:61,代码来源:ManagedImage.cs

示例8: 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;
        }
开发者ID:hamstah,项目名称:geogen,代码行数:84,代码来源:OutputManager.cs

示例9: ColorImageFrameToBitmap

        public System.Drawing.Bitmap ColorImageFrameToBitmap(ColorImageFrame colorFrame)
        {
            byte[] pixelBuffer = new byte[colorFrame.PixelDataLength];
            colorFrame.CopyPixelDataTo(pixelBuffer);


            System.Drawing.Bitmap bitmapFrame = new System.Drawing.Bitmap(colorFrame.Width, colorFrame.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);


            BitmapData bitmapData = bitmapFrame.LockBits(new System.Drawing.Rectangle(0, 0, colorFrame.Width, colorFrame.Height), ImageLockMode.WriteOnly, bitmapFrame.PixelFormat);


            IntPtr intPointer = bitmapData.Scan0;
            //Marshal.Copy(pixelBuffer, 0, intPointer, bitmapData.Width * bitmapData.Height);
            Marshal.Copy(pixelBuffer, 0, intPointer, colorFrame.PixelDataLength);

            bitmapFrame.UnlockBits(bitmapData);

            return bitmapFrame;
           


        }
开发者ID:FACE-Team,项目名称:SceneAnalyzer,代码行数:23,代码来源:Kinect.cs

示例10: 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);
            }
        }
开发者ID:siavash65,项目名称:CSE481-3DAuth,代码行数:65,代码来源:MainWindow.xaml.cs

示例11: ReadBitmap

                /// <summary>Reads contents of device memory as bytes and writes bitmap. Remember, Bitmap uses the BGRA byte order.</summary>
                /// <param name="CQ">Command queue to use</param>
                /// <param name="BlockingRead">TRUE to return only after completed reading.</param>
                /// <param name="events">OpenCL Event associated with this operation</param>
                public System.Drawing.Bitmap ReadBitmap(ComputeCommandQueue CQ, bool BlockingRead, ICollection<ComputeEventBase> events)
                {
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height);
                    System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height);

                    System.Drawing.Imaging.BitmapData bitmapdata = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.WriteOnly,
                            System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                    unsafe
                    {
                        ReadFromDeviceTo((void*)bitmapdata.Scan0, CQ, BlockingRead, events);
                    }

                    bmp.UnlockBits(bitmapdata);

                    return bmp;
                }
开发者ID:hrehfeld,项目名称:opencltemplate,代码行数:21,代码来源:CLCalc.cs

示例12: 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);
            }
        }
开发者ID:Glain,项目名称:FFTPatcher,代码行数:59,代码来源:PSXWorldMap.cs

示例13: Texture2Image

		/// <summary>
		/// Builds a <see cref="Image"/> from an XNA <see cref="Texture2D"/>
		/// <para>... i hate unsafe Methods &lt;.&lt;</para>
		/// </summary>
		/// <param name="Texture"></param>
		/// <returns></returns>
		public static unsafe System.Drawing.Bitmap Texture2Image(Texture2D Texture) {
			uint[] data = new uint[Texture.Width * Texture.Height];
			Texture.GetData<uint>(data);

			System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(Texture.Width, Texture.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
			System.Drawing.Imaging.BitmapData bmpd = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
			uint* ptr = (uint*)bmpd.Scan0.ToPointer();

			for (int x = 0; x < Texture.Width; x++) {
				for (int y = 0; y < Texture.Height; y++) {
					ptr[x + (y * Texture.Width)] = data[x + (y * Texture.Width)];
				}
			}

			bmp.UnlockBits(bmpd);

			return bmp;
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:24,代码来源:DrawHelper.cs

示例14: buttonConvertNew_Click

        private unsafe void buttonConvertNew_Click( object sender, EventArgs _e )
        {
            if ( openFileDialog.ShowDialog( this ) != DialogResult.OK )
                return;
            if ( saveFileDialog.ShowDialog( this ) != DialogResult.OK )
                return;

            FileInfo	SourceFileName = new FileInfo( openFileDialog.FileName );
            FileInfo	TargetFileName = new FileInfo( saveFileDialog.FileName );

            int			W, H;
            float3[,]	Vectors;
            float		x, y, z;
            using ( TargaImage TGA = new TargaImage( SourceFileName.FullName, false ) )
            {
                // Convert
                byte[]		ImageContent = Bitmap.LoadBitmap( TGA.Image, out W, out H );
                Vectors = new float3[W,H];
                int		rha = 0;
                for ( int Y=0; Y < H; Y++ )
                    for ( int X=0; X < W; X++ )
                    {
                        x = 2.0f * ImageContent[rha++] / 255 - 1.0f;
                        y = 2.0f * ImageContent[rha++] / 255 - 1.0f;
                        z = 2.0f * ImageContent[rha++] / 255 - 1.0f;
                        rha++;	// Skip alpha

                        z = Math.Max( 0.0f, z );

                        float	Norm = 1.0f / (float) Math.Sqrt( x*x + y*y + z*z );
                        Vectors[X,Y].x = x * Norm;
                        Vectors[X,Y].y = y * Norm;
                        Vectors[X,Y].z = z * Norm;
                    }
            }

            // Convert to RG improved normal
            double	Nx, Ny;
            double	CosPhi, SinPhi, CosTheta, SinTheta, Normalizer;
            double	a = 1.0, b, c, d = 0.0, e, t;

            ushort[,]	PackedNormal = new ushort[W,H];
            for ( int Y=0; Y < H; Y++ )
                for ( int X=0; X < W; X++ )
                {
                    x = Vectors[X,Y].x;
                    y = Vectors[X,Y].y;
                    z = Vectors[X,Y].z;

                    CosTheta = z;
                    SinTheta = Math.Sqrt( 1 - z*z );
                    Normalizer = 1.0 / Math.Max( 1e-10, SinTheta );
                    CosPhi = x * Normalizer;
                    SinPhi = y * Normalizer;

                    e = SinTheta*SinTheta*SinTheta*SinTheta * CosPhi*CosPhi * SinPhi*SinPhi;
                    c = -SinTheta*SinTheta;
                    b = -CosTheta;

                    double[]	roots = Polynomial.solvePolynomial( a, b, c, d, e );

                    t = Math.Sqrt( 2.0 );
                    for ( int i=0; i < roots.Length; i++ )
                        if ( !double.IsNaN( roots[i] ) && roots[i] >= 0.0 )
                            t = Math.Min( t, roots[i] );

            // 					Nx = t * CosPhi * SinTheta;
            // 					Ny = t * SinPhi * SinTheta;
                    Nx = t * x;
                    Ny = t * y;

                    Vectors[X,Y].x = (float) (0.5 * (1.0 + Nx));
                    Vectors[X,Y].y = (float) (0.5 * (1.0 + Ny));
                    Vectors[X,Y].z = 0.0f;
                }

            // Save as target PNG
            using ( System.Drawing.Bitmap B = new System.Drawing.Bitmap( W, H, System.Drawing.Imaging.PixelFormat.Format32bppRgb ) )
            {
                System.Drawing.Imaging.BitmapData	LockedBitmap = B.LockBits( new System.Drawing.Rectangle( 0, 0, W, H ), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb );

                for ( int Y=0; Y < H; Y++ )
                {
                    byte*	pScanline = (byte*) LockedBitmap.Scan0 + LockedBitmap.Stride * Y;
                    for ( int X=0; X < W; X++ )
                    {
                        *pScanline++ = 0;
                        *pScanline++ = (byte) (255 * Vectors[X,Y].y);
                        *pScanline++ = (byte) (255 * Vectors[X,Y].x);
                        *pScanline++ = 0xFF;
                    }
                }

                B.UnlockBits( LockedBitmap );

                B.Save( TargetFileName.FullName );
            }
        }
开发者ID:Patapom,项目名称:GodComplex,代码行数:98,代码来源:Form1.cs

示例15: GetPreview

        /// <summary>
        /// Gets an image for the given job and preview
        /// </summary>
        /// <remarks>
        /// Only incorporates sizing and aspect ratio into preview image.
        /// </remarks>
        /// <param name="job">The encode job to preview.</param>
        /// <param name="previewNumber">The index of the preview to get (0-based).</param>
        /// <returns>An image with the requested preview.</returns>
        public BitmapImage GetPreview(EncodeJob job, int previewNumber)
        {
            hb_title_s title = this.GetOriginalTitle(job.Title);

            hb_job_s nativeJob = InteropUtilities.ReadStructure<hb_job_s>(title.job);
            List<IntPtr> allocatedMemory = this.ApplyJob(ref nativeJob, job);

            // There are some problems with getting previews with deinterlacing. Disabling for now.
            nativeJob.deinterlace = 0;

            // Create a new job pointer from our modified job object
            IntPtr newJob = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(hb_job_s)));
            Marshal.StructureToPtr(nativeJob, newJob, false);
            allocatedMemory.Add(newJob);

            int outputWidth = nativeJob.width;
            int outputHeight = nativeJob.height;
            int imageBufferSize = outputWidth * outputHeight * 4;
            IntPtr nativeBuffer = Marshal.AllocHGlobal(imageBufferSize);
            allocatedMemory.Add(nativeBuffer);
            HBFunctions.hb_set_job(this.hbHandle, job.Title, ref nativeJob);
            HBFunctions.hb_get_preview(this.hbHandle, ref title, previewNumber, nativeBuffer);

            // Copy the filled image buffer to a managed array.
            byte[] managedBuffer = new byte[imageBufferSize];
            Marshal.Copy(nativeBuffer, managedBuffer, 0, imageBufferSize);

            InteropUtilities.FreeMemory(allocatedMemory);

            var bitmap = new System.Drawing.Bitmap(outputWidth, outputHeight);
            System.Drawing.Imaging.BitmapData bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, outputWidth, outputHeight), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);

            IntPtr ptr = bitmapData.Scan0;

            for (int i = 0; i < nativeJob.height; i++)
            {
                Marshal.Copy(managedBuffer, i * nativeJob.width * 4, ptr, nativeJob.width * 4);
                ptr = IntPtr.Add(ptr, bitmapData.Stride);
            }

            bitmap.UnlockBits(bitmapData);

            using (var memoryStream = new MemoryStream())
            {
                try
                {
                    bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Bmp);
                }
                finally
                {
                    bitmap.Dispose();
                }

                var wpfBitmap = new BitmapImage();
                wpfBitmap.BeginInit();
                wpfBitmap.CacheOption = BitmapCacheOption.OnLoad;
                wpfBitmap.StreamSource = memoryStream;
                wpfBitmap.EndInit();
                wpfBitmap.Freeze();

                return wpfBitmap;
            }
        }
开发者ID:kolanos,项目名称:HandBrake,代码行数:72,代码来源:HandBrakeInstance.cs


注:本文中的System.Drawing.Bitmap.UnlockBits方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。