當前位置: 首頁>>代碼示例>>C#>>正文


C# Bitmap.Bounds方法代碼示例

本文整理匯總了C#中System.Drawing.Bitmap.Bounds方法的典型用法代碼示例。如果您正苦於以下問題:C# Bitmap.Bounds方法的具體用法?C# Bitmap.Bounds怎麽用?C# Bitmap.Bounds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Drawing.Bitmap的用法示例。


在下文中一共展示了Bitmap.Bounds方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CustomTerrainBitmap

        public static Bitmap CustomTerrainBitmap(World world)
        {
            var map = world.Map;
            var size = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height));
            var bitmap = new Bitmap(size, size);
            var bitmapData = bitmap.LockBits(bitmap.Bounds(),
                ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            unsafe
            {
                int* c = (int*)bitmapData.Scan0;

                for (var x = 0; x < map.Bounds.Width; x++)
                    for (var y = 0; y < map.Bounds.Height; y++)
                    {
                        var mapX = x + map.Bounds.Left;
                        var mapY = y + map.Bounds.Top;
                        var custom = map.CustomTerrain[mapX, mapY];
                        if (custom == null)
                            continue;
                        *(c + (y * bitmapData.Stride >> 2) + x) = world.TileSet.Terrain[custom].Color.ToArgb();
                    }
            }

            bitmap.UnlockBits(bitmapData);
            return bitmap;
        }
開發者ID:RunCraze,項目名稱:OpenRA,代碼行數:27,代碼來源:Minimap.cs

示例2: CustomTerrainBitmap

        public static Bitmap CustomTerrainBitmap(World world)
        {
            var map = world.Map;
            var b = map.Bounds;

            var size = Exts.NextPowerOf2(Math.Max(b.Width, b.Height));
            var bitmap = new Bitmap(size, size);
            var bitmapData = bitmap.LockBits(bitmap.Bounds(),
                ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            unsafe
            {
                var colors = (int*)bitmapData.Scan0;
                var stride = bitmapData.Stride / 4;
                for (var y = 0; y < b.Height; y++)
                {
                    for (var x = 0; x < b.Width; x++)
                    {
                        var mapX = x + b.Left;
                        var mapY = y + b.Top;
                        var custom = map.CustomTerrain[mapX, mapY];
                        if (custom == byte.MaxValue)
                            continue;
                        colors[y * stride + x] = world.TileSet[custom].Color.ToArgb();
                    }
                }
            }

            bitmap.UnlockBits(bitmapData);
            return bitmap;
        }
開發者ID:RobotCaleb,項目名稱:OpenRA,代碼行數:31,代碼來源:Minimap.cs

示例3: RenderResourceType

        public static ResourceTemplate RenderResourceType(ResourceTypeInfo info, string[] exts, Palette p)
        {
            var image = info.EditorSprite;
            using (var s = FileSystem.OpenWithExts(image, exts))
            {
                // TODO: Do this properly
                var shp = new ShpReader(s) as ISpriteSource;
                var frame = shp.Frames.Last();

                var bitmap = new Bitmap(frame.Size.Width, frame.Size.Height, PixelFormat.Format8bppIndexed);
                bitmap.Palette = p.AsSystemPalette();
                var data = bitmap.LockBits(bitmap.Bounds(),
                    ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

                unsafe
                {
                    byte* q = (byte*)data.Scan0.ToPointer();
                    var stride = data.Stride;

                    for (var i = 0; i < frame.Size.Width; i++)
                        for (var j = 0; j < frame.Size.Height; j++)
                            q[j * stride + i] = frame.Data[i + frame.Size.Width * j];
                }

                bitmap.UnlockBits(data);
                return new ResourceTemplate { Bitmap = bitmap, Info = info, Value = shp.Frames.Count() - 1 };
            }
        }
開發者ID:Generalcamo,項目名稱:OpenRA,代碼行數:28,代碼來源:RenderUtils.cs

示例4: ActorsBitmap

        public static Bitmap ActorsBitmap(World world)
        {
            var map = world.Map;
            var size = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height));
            var bitmap = new Bitmap(size, size);
            var bitmapData = bitmap.LockBits(bitmap.Bounds(),
                ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            unsafe
            {
                int* c = (int*)bitmapData.Scan0;

                foreach (var t in world.ActorsWithTrait<IRadarSignature>())
                {
                    if (world.FogObscures(t.Actor))
                        continue;

                    var color = t.Trait.RadarSignatureColor(t.Actor);
                    foreach (var cell in t.Trait.RadarSignatureCells(t.Actor))
                        if (world.Map.IsInMap(cell))
                            *(c + ((cell.Y - world.Map.Bounds.Top) * bitmapData.Stride >> 2) + cell.X - world.Map.Bounds.Left) = color.ToArgb();
                }
            }

            bitmap.UnlockBits(bitmapData);
            return bitmap;
        }
開發者ID:Tsher,項目名稱:OpenRA,代碼行數:27,代碼來源:Minimap.cs

示例5: AddStaticResources

        // Add the static resources defined in the map; if the map lives
        // in a world use AddCustomTerrain instead
        public static Bitmap AddStaticResources(Map map, Bitmap terrainBitmap)
        {
            Bitmap terrain = new Bitmap(terrainBitmap);
            var tileset = Rules.TileSets[map.Tileset];

            var bitmapData = terrain.LockBits(terrain.Bounds(),
                ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            unsafe
            {
                int* c = (int*)bitmapData.Scan0;

                for (var x = 0; x < map.Bounds.Width; x++)
                    for (var y = 0; y < map.Bounds.Height; y++)
                    {
                        var mapX = x + map.Bounds.Left;
                        var mapY = y + map.Bounds.Top;
                        if (map.MapResources.Value[mapX, mapY].type == 0)
                            continue;

                        var res = Rules.Info["world"].Traits.WithInterface<ResourceTypeInfo>()
                                .Where(t => t.ResourceType == map.MapResources.Value[mapX, mapY].type)
                                .Select(t => t.TerrainType).FirstOrDefault();
                        if (res == null)
                            continue;

                        *(c + (y * bitmapData.Stride >> 2) + x) = tileset.Terrain[res].Color.ToArgb();
                    }
            }

            terrain.UnlockBits(bitmapData);

            return terrain;
        }
開發者ID:Tsher,項目名稱:OpenRA,代碼行數:36,代碼來源:Minimap.cs

示例6: ActorsBitmap

        public static Bitmap ActorsBitmap(World world)
        {
            var map = world.Map;
            var b = map.Bounds;

            var size = Exts.NextPowerOf2(Math.Max(b.Width, b.Height));
            var bitmap = new Bitmap(size, size);
            var bitmapData = bitmap.LockBits(bitmap.Bounds(),
                ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            unsafe
            {
                var colors = (int*)bitmapData.Scan0;
                var stride = bitmapData.Stride / 4;
                foreach (var t in world.ActorsWithTrait<IRadarSignature>())
                {
                    if (world.FogObscures(t.Actor))
                        continue;

                    var color = t.Trait.RadarSignatureColor(t.Actor);
                    foreach (var cell in t.Trait.RadarSignatureCells(t.Actor))
                    {
                        var uv = Map.CellToMap(map.TileShape, cell);
                        if (b.Contains(uv.X, uv.Y))
                            colors[(uv.Y - b.Top) * stride + uv.X - b.Left] = color.ToArgb();
                    }
                }
            }

            bitmap.UnlockBits(bitmapData);
            return bitmap;
        }
開發者ID:RobotCaleb,項目名稱:OpenRA,代碼行數:32,代碼來源:Minimap.cs

示例7: RenderResourceType

        public static ResourceTemplate RenderResourceType(ResourceTypeInfo info, string[] exts, Palette p)
        {
            var image = info.SpriteNames[0];
            using (var s = FileSystem.OpenWithExts(image, exts))
            {
                var shp = new ShpReader(s);
                var frame = shp[shp.ImageCount - 1];

                var bitmap = new Bitmap(shp.Width, shp.Height, PixelFormat.Format8bppIndexed);
                bitmap.Palette = p.AsSystemPalette();
                var data = bitmap.LockBits(bitmap.Bounds(),
                    ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

                unsafe
                {
                    byte* q = (byte*)data.Scan0.ToPointer();
                    var stride = data.Stride;

                    for (var i = 0; i < shp.Width; i++)
                        for (var j = 0; j < shp.Height; j++)
                            q[j * stride + i] = frame.Image[i + shp.Width * j];
                }

                bitmap.UnlockBits(data);
                return new ResourceTemplate { Bitmap = bitmap, Info = info, Value = shp.ImageCount - 1 };
            }
        }
開發者ID:sonygod,項目名稱:OpenRA-Dedicated-20120504,代碼行數:27,代碼來源:RenderUtils.cs

示例8: FastCopyIntoSprite

        public static void FastCopyIntoSprite(Sprite dest, Bitmap src)
        {
            var destStride = dest.sheet.Size.Width;
            var width = dest.bounds.Width;
            var height = dest.bounds.Height;

            var srcData = src.LockBits(src.Bounds(),
                ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            unsafe
            {
                var c = (int*)srcData.Scan0;

                // Cast the data to an int array so we can copy the src data directly
                fixed (byte* bd = &dest.sheet.Data[0])
                {
                    var data = (int*)bd;
                    var x = dest.bounds.Left;
                    var y = dest.bounds.Top;

                    for (var j = 0; j < height; j++)
                        for (var i = 0; i < width; i++)
                            data[(y + j) * destStride + x + i] = *(c + (j * srcData.Stride >> 2) + i);
                }
            }

            src.UnlockBits(srcData);
        }
開發者ID:RunCraze,項目名稱:OpenRA,代碼行數:28,代碼來源:Util.cs

示例9: RenderResourceType

        public static ResourceTemplate RenderResourceType(ResourceTypeInfo info, TileSet tileset, IPalette p)
        {
            var image = ResolveFilename(info.EditorSprite, tileset);
            using (var s = GlobalFileSystem.Open(image))
            {
                // TODO: Do this properly
                var shp = new ShpTDSprite(s);
                var frame = shp.Frames.Last();

                var bitmap = new Bitmap(frame.Size.Width, frame.Size.Height, PixelFormat.Format8bppIndexed);
                bitmap.Palette = p.AsSystemPalette();
                var data = bitmap.LockBits(bitmap.Bounds(),
                    ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

                unsafe
                {
                    var q = (byte*)data.Scan0.ToPointer();
                    var stride = data.Stride;

                    for (var i = 0; i < frame.Size.Width; i++)
                        for (var j = 0; j < frame.Size.Height; j++)
                            q[j * stride + i] = frame.Data[i + frame.Size.Width * j];
                }

                bitmap.UnlockBits(data);
                return new ResourceTemplate { Bitmap = bitmap, Info = info, Value = shp.Frames.Count - 1 };
            }
        }
開發者ID:ushardul,項目名稱:OpenRA,代碼行數:28,代碼來源:RenderUtils.cs

示例10: TerrainBitmap

        public static Bitmap TerrainBitmap(TileSet tileset, Map map, bool actualSize = false)
        {
            var isDiamond = map.TileShape == TileShape.Diamond;
            var b = map.Bounds;

            // Fudge the heightmap offset by adding as much extra as we need / can.
            // This tries to correct for our incorrect assumption that MPos == PPos
            var heightOffset = Math.Min(map.MaximumTerrainHeight, map.MapSize.Y - b.Bottom);
            var width = b.Width;
            var height = b.Height + heightOffset;

            var bitmapWidth = width;
            if (isDiamond)
                bitmapWidth = 2 * bitmapWidth - 1;

            if (!actualSize)
                bitmapWidth = height = Exts.NextPowerOf2(Math.Max(bitmapWidth, height));

            var terrain = new Bitmap(bitmapWidth, height);

            var bitmapData = terrain.LockBits(terrain.Bounds(),
                ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

            var mapTiles = map.MapTiles.Value;

            unsafe
            {
                var colors = (int*)bitmapData.Scan0;
                var stride = bitmapData.Stride / 4;
                for (var y = 0; y < height; y++)
                {
                    for (var x = 0; x < width; x++)
                    {
                        var uv = new MPos(x + b.Left, y + b.Top);
                        var type = tileset.GetTileInfo(mapTiles[uv]);
                        var leftColor = type != null ? type.LeftColor : Color.Black;

                        if (isDiamond)
                        {
                            // Odd rows are shifted right by 1px
                            var dx = uv.V & 1;
                            var rightColor = type != null ? type.RightColor : Color.Black;
                            if (x + dx > 0)
                                colors[y * stride + 2 * x + dx - 1] = leftColor.ToArgb();

                            if (2 * x + dx < stride)
                                colors[y * stride + 2 * x + dx] = rightColor.ToArgb();
                        }
                        else
                            colors[y * stride + x] = leftColor.ToArgb();
                    }
                }
            }

            terrain.UnlockBits(bitmapData);
            return terrain;
        }
開發者ID:rhamilton1415,項目名稱:OpenRA,代碼行數:57,代碼來源:Minimap.cs

示例11: AsBitmap

        public Bitmap AsBitmap()
        {
            var d = GetData();
            var dataStride = 4 * Size.Width;
            var bitmap = new Bitmap(Size.Width, Size.Height);

            var bd = bitmap.LockBits(bitmap.Bounds(),
                ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
            for (var y = 0; y < Size.Height; y++)
                Marshal.Copy(d, y * dataStride, IntPtr.Add(bd.Scan0, y * bd.Stride), dataStride);
            bitmap.UnlockBits(bd);

            return bitmap;
        }
開發者ID:ushardul,項目名稱:OpenRA,代碼行數:14,代碼來源:Sheet.cs

示例12: FastCopyIntoSprite

		public static void FastCopyIntoSprite(Sprite dest, Bitmap src)
		{
			var createdTempBitmap = false;
			if (src.PixelFormat != PixelFormat.Format32bppArgb)
			{
				src = src.CloneWith32bbpArgbPixelFormat();
				createdTempBitmap = true;
			}

			try
			{
				var destData = dest.Sheet.GetData();
				var destStride = dest.Sheet.Size.Width;
				var width = dest.Bounds.Width;
				var height = dest.Bounds.Height;

				var srcData = src.LockBits(src.Bounds(),
					ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);

				unsafe
				{
					var c = (int*)srcData.Scan0;

					// Cast the data to an int array so we can copy the src data directly
					fixed (byte* bd = &destData[0])
					{
						var data = (int*)bd;
						var x = dest.Bounds.Left;
						var y = dest.Bounds.Top;

						for (var j = 0; j < height; j++)
						{
							for (var i = 0; i < width; i++)
							{
								var cc = Color.FromArgb(*(c + (j * srcData.Stride >> 2) + i));
								data[(y + j) * destStride + x + i] = PremultiplyAlpha(cc).ToArgb();
							}
						}
					}
				}

				src.UnlockBits(srcData);
			}
			finally
			{
				if (createdTempBitmap)
					src.Dispose();
			}
		}
開發者ID:Roger-luo,項目名稱:OpenRA,代碼行數:49,代碼來源:Util.cs

示例13: FastCopyIntoSprite

		public static void FastCopyIntoSprite(Sprite dest, Bitmap src)
		{
			var data = dest.sheet.Data;
			var dataStride = dest.sheet.Size.Width * 4;
			var x = dest.bounds.Left * 4;
			var width = dest.bounds.Width * 4;
			var y = dest.bounds.Top;
			var height = dest.bounds.Height;

			var bd = src.LockBits(src.Bounds(),
				ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
			for (var row = 0; row < height; row++)
				Marshal.Copy(IntPtr.Add(bd.Scan0, row * bd.Stride), data, (y + row) * dataStride + x, width);
			src.UnlockBits(bd);
		}
開發者ID:Berzeger,項目名稱:OpenRA,代碼行數:15,代碼來源:Util.cs

示例14: Initialize

        public override void Initialize(WidgetArgs args)
        {
            base.Initialize(args);

            hueBitmap = new Bitmap(256, 256);
            hueSprite = new Sprite(new Sheet(new Size(256, 256)), new Rectangle(0, 0, 256, 1), TextureChannel.Alpha);

            var bitmapData = hueBitmap.LockBits(hueBitmap.Bounds(),
                ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
            unsafe
            {
                int* c = (int*)bitmapData.Scan0;
                for (var h = 0; h < 256; h++)
                    *(c + h) = HSLColor.FromHSV(h/255f, 1, 1).RGB.ToArgb();
            }
            hueBitmap.UnlockBits(bitmapData);

            hueSprite.sheet.Texture.SetData(hueBitmap);
        }
開發者ID:Generalcamo,項目名稱:OpenRA,代碼行數:19,代碼來源:HueSliderWidget.cs

示例15: RenderTemplate

        public Bitmap RenderTemplate(ushort id, Palette p)
        {
            var template = TileSet.Templates[id];
            var templateData = templates[id];

            var bitmap = new Bitmap(TileSize * template.Size.X, TileSize * template.Size.Y,
                PixelFormat.Format8bppIndexed);

            bitmap.Palette = p.AsSystemPalette();

            var data = bitmap.LockBits(bitmap.Bounds(),
                ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);

            unsafe
            {
                var q = (byte*)data.Scan0.ToPointer();
                var stride = data.Stride;

                for (var u = 0; u < template.Size.X; u++)
                {
                    for (var v = 0; v < template.Size.Y; v++)
                    {
                        var rawImage = templateData[u + v * template.Size.X];
                        if (rawImage != null && rawImage.Length > 0)
                        {
                            for (var i = 0; i < TileSize; i++)
                                for (var j = 0; j < TileSize; j++)
                                    q[(v * TileSize + j) * stride + u * TileSize + i] = rawImage[i + TileSize * j];
                        }
                        else
                        {
                            for (var i = 0; i < TileSize; i++)
                                for (var j = 0; j < TileSize; j++)
                                    q[(v * TileSize + j) * stride + u * TileSize + i] = 0;
                        }
                    }
                }
            }

            bitmap.UnlockBits(data);
            return bitmap;
        }
開發者ID:RunCraze,項目名稱:OpenRA,代碼行數:42,代碼來源:TileSetRenderer.cs


注:本文中的System.Drawing.Bitmap.Bounds方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。