当前位置: 首页>>代码示例>>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;未经允许,请勿转载。