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


C# BitmapBuffer.SetPixel方法代码示例

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


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

示例1: Trim

        /// <summary>
        /// copies this bitmap and trims out transparent pixels, returning the offset to the topleft pixel
        /// </summary>
        public BitmapBuffer Trim(out int xofs, out int yofs)
        {
            int minx = int.MaxValue;
            int maxx = int.MinValue;
            int miny = int.MaxValue;
            int maxy = int.MinValue;
            for (int y = 0; y < Height; y++)
                for (int x = 0; x < Width; x++)
                {
                    int pixel = GetPixel(x, y);
                    int a = (pixel >> 24) & 0xFF;
                    if (a != 0)
                    {
                        minx = Math.Min(minx, x);
                        maxx = Math.Max(maxx, x);
                        miny = Math.Min(miny, y);
                        maxy = Math.Max(maxy, y);
                    }
                }

            if (minx == int.MaxValue || maxx == int.MinValue || miny == int.MaxValue || minx == int.MinValue)
            {
                xofs = yofs = 0;
                return new BitmapBuffer(0, 0);
            }

            int w = maxx - minx + 1;
            int h = maxy - miny + 1;
            BitmapBuffer bbRet = new BitmapBuffer(w, h);
            for (int y = 0; y < h; y++)
                for (int x = 0; x < w; x++)
                {
                    bbRet.SetPixel(x, y, GetPixel(x + minx, y + miny));
                }

            xofs = minx;
            yofs = miny;
            return bbRet;
        }
开发者ID:cas1993per,项目名称:bizhawk,代码行数:42,代码来源:BitmapBuffer.cs

示例2: Close

		/// <summary>
		/// Closes this instance for for further resource loading. Will result in a texture atlasing operation.
		/// If the close operation is forever, then internal backup copies of resources will be freed, but it can never be reopened.
		/// This function may take some time to run, as it is 
		/// </summary>
		public unsafe void Close(bool forever = true)
		{
			AssertIsOpen(true);
			IsOpened = false;
			IsClosedForever = forever;

			//first, cleanup old stuff
			foreach (var tex in ManagedTextures)
				tex.Dispose();
			ManagedTextures.Clear();

			//prepare input for atlas process and perform atlas
			//add 2 extra pixels for padding on all sides
			List<TexAtlas.RectItem> atlasItems = new List<TexAtlas.RectItem>();
			foreach (var kvp in ArtLooseTextureAssociation)
				atlasItems.Add(new TexAtlas.RectItem(kvp.Value.Width+2, kvp.Value.Height+2, kvp));
			var results = TexAtlas.PackAtlas(atlasItems);

			//this isnt supported yet:
			if (results.Atlases.Count > 1)
				throw new InvalidOperationException("Art files too big for atlas");

			//prepare the output buffer
			BitmapBuffer bmpResult = new BitmapBuffer(results.Atlases[0].Size);

			//for each item, copy it into the output buffer and set the tex parameters on them
			for (int i = 0; i < atlasItems.Count; i++)
			{
				var item = results.Atlases[0].Items[i];
				var artAndBitmap = (KeyValuePair<Art, BitmapBuffer>)item.Item;
				var art = artAndBitmap.Key;
				var bitmap = artAndBitmap.Value;

				int w = bitmap.Width;
				int h = bitmap.Height;
				int dx = item.X + 1;
				int dy = item.Y + 1;
				for (int y = 0; y < h; y++)
					for (int x = 0; x < w; x++)
					{
						int pixel = bitmap.GetPixel(x, y);
						bmpResult.SetPixel(x+dx,y+dy,pixel);
					}

				var myDestBitmap = bmpResult;
				float myDestWidth = (float)myDestBitmap.Width;
				float myDestHeight = (float)myDestBitmap.Height;

				art.u0 = dx / myDestWidth;
				art.v0 = dy / myDestHeight;
				art.u1 = (dx + w) / myDestWidth;
				art.v1 = (dy + h) / myDestHeight;
				art.Width = w;
				art.Height = h;
			}

			//if we're closed forever, then forget all the original bitmaps
			if (forever)
			{
				foreach (var kvp in ArtLooseTextureAssociation)
					kvp.Value.Dispose();
				ArtLooseTextureAssociation.Clear();
			}

			//create a physical texture
			var texture = Owner.LoadTexture(bmpResult);
			ManagedTextures.Add(texture);

			//oops, we couldn't do this earlier.
			foreach (var art in ManagedArts)
				art.BaseTexture = texture;
		}
开发者ID:CadeLaRen,项目名称:BizHawk,代码行数:77,代码来源:ArtManager.cs


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