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


C# RuntimeAddin.GetResource方法代码示例

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


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

示例1: InternalGetStockIdFromResource

		static string InternalGetStockIdFromResource (RuntimeAddin addin, string id, Gtk.IconSize size)
		{
			if (!id.StartsWith ("res:", StringComparison.Ordinal))
				return id;

			id = id.Substring (4);
			int addinId = GetAddinId (addin);
			Dictionary<string, string> hash = addinIcons[addinId];
			string stockId = "__asm" + addinId + "__" + id + "__" + size;
			if (!hash.ContainsKey (stockId)) {
				System.IO.Stream stream = addin.GetResource (id);
				if (stream != null) {
					Gdk.Pixbuf pix1, pix2 = null;
					using (stream) {
						pix1 = new Gdk.Pixbuf (stream);
					}
					stream = addin.GetResource2x (id);
					if (stream != null) {
						using (stream) {
							pix2 = new Gdk.Pixbuf (stream);
						}
					}
					AddToIconFactory (stockId, pix1, pix2, size);
				}
				hash[stockId] = stockId;
			}
			return stockId;
		}
开发者ID:alexrp,项目名称:monodevelop,代码行数:28,代码来源:ImageService.cs

示例2: LoadStockIcon

		static Xwt.Drawing.Image LoadStockIcon (RuntimeAddin addin, string stockId, string resource, string imageFile, string iconId, Gtk.IconSize iconSize, string animation, bool forceWildcard)
		{
			try {
				Gdk.Pixbuf pixbuf = null, pixbuf2x = null;
				AnimatedIcon animatedIcon = null;
				Func<Stream[]> imageLoader = null;

				if (!string.IsNullOrEmpty (resource) || !string.IsNullOrEmpty (imageFile)) {
					// using the stream directly produces a gdk warning.
					byte[] buffer;

					if (resource != null) {
						imageLoader = delegate {
							var stream = addin.GetResource (resource);
							var stream2x = addin.GetResource2x (resource);
							if (stream2x == null)
								return new [] { stream };
							else
								return new [] { stream, stream2x };
						};
					}
					else {
						imageLoader = delegate {
							var file = addin.GetFilePath (imageFile);
							var stream = File.OpenRead (file);
							Stream stream2x = null;
							var file2x = Path.Combine (Path.GetDirectoryName (file), Path.GetFileNameWithoutExtension (file) + "@2x" + Path.GetExtension (file));
							if (File.Exists (file2x))
								stream2x = File.OpenRead (file2x);
							else {
								file2x = file + "@2x";
								if (File.Exists (file2x))
									stream2x = File.OpenRead (file2x);
							}
							if (stream2x == null)
								return new [] { stream };
							else
								return new [] { stream, stream2x };
						};
					}
					var streams = imageLoader ();

					var st = streams[0];
					var st2x = streams.Length > 1 ? streams[1] : null;

					using (st) {
						if (st == null || st.Length < 0) {
							LoggingService.LogError ("Did not find resource '{0}' in addin '{1}' for icon '{2}'",
								resource, addin.Id, stockId);
							return null;
						}
						buffer = new byte [st.Length];
						st.Read (buffer, 0, (int)st.Length);
					}
					pixbuf = new Gdk.Pixbuf (buffer);

					using (st2x) {
						if (st2x != null && st2x.Length >= 0) {
							buffer = new byte [st2x.Length];
							st2x.Read (buffer, 0, (int)st2x.Length);
							pixbuf2x = new Gdk.Pixbuf (buffer);
						}
					}

				} else if (!string.IsNullOrEmpty (iconId)) {
					var id = GetStockIdForImageSpec (addin, iconId, iconSize);
					pixbuf = GetPixbuf (id, iconSize);
					pixbuf2x = Get2xIconVariant (pixbuf);
					// This may be an animation, get it
					animationFactory.TryGetValue (id, out animatedIcon);
				} else if (!string.IsNullOrEmpty (animation)) {
					string id = GetStockIdForImageSpec (addin, "animation:" + animation, iconSize);
					pixbuf = GetPixbuf (id, iconSize);
					// This *should* be an animation
					animationFactory.TryGetValue (id, out animatedIcon);
				}

				Gtk.IconSize size = forceWildcard? Gtk.IconSize.Invalid : iconSize;
				if (pixbuf != null)
					AddToIconFactory (stockId, pixbuf, pixbuf2x, size);

				if (animatedIcon != null)
					AddToAnimatedIconFactory (stockId, animatedIcon);

				var img = Xwt.Toolkit.CurrentEngine.WrapImage (pixbuf);
				if (pixbuf2x != null) {
					var img2x = Xwt.Toolkit.CurrentEngine.WrapImage (pixbuf2x);
					img = Xwt.Drawing.Image.CreateMultiResolutionImage (new [] { img, img2x });
				}
				if (imageLoader != null)
					img.SetStreamSource (imageLoader);

				return img;

			} catch (Exception ex) {
				LoggingService.LogError (string.Format ("Error loading icon '{0}'", stockId), ex);
				return null;
			}
		}
开发者ID:pabloescribanoloza,项目名称:monodevelop,代码行数:99,代码来源:ImageService.cs


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