我正在构建的应用程序要求我的用户在此图像甚至有可能加载之前设置4条信息.这个图像是应用程序的中心部分,因此破碎的图像链接使整个事物看起来像是被塞住了.我想让另一张图片取代404.
有任何想法吗?我想避免为此编写自定义指令.
我很惊讶我找不到类似的问题,特别是当文档中的第一个问题是同一个问题时!
有没有办法确定图像路径是否会导致实际图像,即检测到图像无法在Javascript中加载.
对于Web应用程序,我正在解析xml文件并从图像路径列表中动态创建HTML图像.服务器上可能不再存在某些映像路径,因此我希望通过检测哪些映像无法加载并删除该HTML img元素来优雅地失败.
注意JQuery解决方案无法使用(老板不想使用JQuery,是的,我知道不要让我开始).我知道在JQuery中检测图像何时加载的方法,但不知道它是否失败.
我的代码创建img元素,但我如何检测img路径是否导致无法加载图像?
var imgObj = new Image(); // document.createElement("img");
imgObj.src = src;
Run Code Online (Sandbox Code Playgroud) 我需要动态设置图像源,请注意我的图像位于网络上的某个位置,这是我的代码
BitmapImage logo = new BitmapImage();
logo.BeginInit();
logo.UriSource = new Uri(@"pack://application:,,,\\myserver\\folder1\\Customer Data\\sample.png");
logo.EndInit(); // Getting the exception here
ImageViewer1.Source = logo;
Run Code Online (Sandbox Code Playgroud)
例外:
无法识别URI前缀
我有一个BitmapImage
我在WPF应用程序中使用的,后来我想将它作为字节数组保存到数据库中(我猜这是最好的方法),我该如何执行这种转换?
或者,是否有更好的方法将BitmapImage
(或其任何基类,BitmapSource
或ImageSource
)保存到数据存储库?
我有一个项目需要窗口中的图像.这是一个静态图像,我通过"添加>现有项目"添加.它存在于项目的根目录中.
我在测试页面中引用图像,如此 -
<Page x:Class="Critter.Pages.Test"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Test">
<Image Source="bug.png"/>
</Page>
Run Code Online (Sandbox Code Playgroud)
问题是我收到一条消息,说它无法找到或者它的构建操作不是资源但是它存在并且它的构建操作是IS资源.如果我创建一个新的应用程序,然后将其扔在窗口上,那么它工作正常.
任何帮助都会很棒.
我已经搜索了一种在java项目中嵌入资源的方法(使用Eclipse v3.6.0),然后在控件中使用该嵌入式资源(例如JLabel
).我见过从文件系统引用资源的方法.项目开发完成后,我想将该应用程序发布为可执行文件.应该注意,这些可执行文件将被部署/启动到Windows,*NIX和Linux平台.
我知道这可以在Visual Studio世界中完成,但是我很不熟悉如何在Java/Eclipse IDE中执行此操作.作为一个附带问题,我如何让Eclipse将项目创建为可执行文件以便可以启动它?
任何帮助是极大的赞赏.
标记
更新1:
根据BalusC的回复,我想分享我解决问题的代码.我的类在" Viking.Test
" 的包下,然后我将图像文件放在包" Viking.Test.Resources
"下.这都是在Eclipse中完成的,用于将图像导入到项目中.
Project/src/Viking/Test/Resources
为'Into folder'参数选择" "在源文件中我添加了以下代码以将图像插入到JLabel
(LblLogo
)中
try
{
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream input = classLoader.getResourceAsStream(
"Viking/Test/Resources/MyImage.jpg");
Image logo = ImageIO.read(input);
LblLogo = new JLabel( new ImageIcon( logo ) );
LblLogo.setBounds(20, 11, 210, 93);
getContentPane().add(LblLogo);
}
catch ( IOException e ) { }
Run Code Online (Sandbox Code Playgroud) 我很难在堆栈布局中在内容页面上显示图像.我查看了Xamarin API文档并找到了Xamarin.Forms.Image.Source属性,但没有示例代码来查看它是如何编写的.我还检查了它是如何用C#编写的,似乎与我的代码在文件名路径方面相匹配,但在Xamarin中,它可能略有不同,因为它是第一次这样做.我目前通过Visual Studio 2013中的Android模拟器(Google Nexus 5)测试的代码运行正常,但图像未显示除外.
图片来源:
new Image
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
Source = "/Assets/xamarin_logo.png",
},
Run Code Online (Sandbox Code Playgroud)
完整代码:
public NFCPage()
{
StackLayout stackLayout = new StackLayout // instantiate a StackLayout object to layout its children
{
Spacing = 5, // amount of spae between each child element
//HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.FillAndExpand, // defines how the elements should be laid out; fill the entire width of the content to the screen
BackgroundColor = Color.Blue, …
Run Code Online (Sandbox Code Playgroud) 如何在硬盘驱动器中显示UIImageView组件中的图像?
我有一个名为"images"的本地文件夹,并希望通过相对路径访问它,因为我想用应用程序打包图像.
我需要将System.Drawing.Bitmap转换为System.Windows.Media.ImageSource类,以便将其绑定到WizardPage(扩展WPF工具包)的HeaderImage控件中.位图设置为我编写的程序集的资源.它被引用如下:
public Bitmap GetBitmap
{
get
{
Bitmap bitmap = new Bitmap(Resources.my_banner);
return bitmap;
}
}
public ImageSource HeaderBitmap
{
get
{
ImageSourceConverter c = new ImageSourceConverter();
return (ImageSource) c.ConvertFrom(GetBitmap);
}
}
Run Code Online (Sandbox Code Playgroud)
这个转换器是我在这里找到的:http://www.codeproject.com/Questions/621920/How-to-convert-Bitmap-to-ImageSource 我得到一个NullReferenceException at
return (ImageSource) c.ConvertFrom(Resources.my_banner);
如何初始化ImageSource以避免此异常?或者还有另一种方式吗?我想在之后使用它:
<xctk:WizardPage x:Name="StartPage" Height="500" Width="700"
HeaderImage="{Binding HeaderBitmap}" Enter="StartPage_OnEnter"
Run Code Online (Sandbox Code Playgroud)
提前感谢您的任何答案.
如何使用c#ImageSource
从MemoryStream
WPF中获取?或转换MemoryStream
,以ImageSource
显示它在WPF的形象?
imagesource ×10
c# ×5
wpf ×5
resources ×2
.net ×1
angularjs ×1
bitmap ×1
bitmapimage ×1
buildaction ×1
eclipse ×1
image ×1
ios ×1
iphone ×1
java ×1
javascript ×1
memorystream ×1
objective-c ×1
onerror ×1
xamarin ×1