我有一个asp.net mvc项目.在一个特殊的视图中,我在我的proect中调用来自不同不同文件夹的四个图像.
有时无法找到图像.我想为每个文件夹设置一个图像,因为所有4个文件夹包含不同大小的图像,所以我需要为每个文件夹设置特定大小的图像.
当图像找不到任何方法时,我怎么能显示默认图像.i表示当目录没有我在视图中调用的图像时调用none.png.
他们是在没有找到图像的情况下显示图像的任何方式.
任何方式在asp.net 4 MVC 3中使用web.config或设置其他任何东西.
我用来从资源中StreamResourceInfo.Stream获取BitmapImage资源.使用后流Close和Dispose流是否正确?我问,因为在内存分析器中,如果我这样做,我会收到错误.内存分析器表示已处理的实例尚未进行GCed.
如果我在网上看,我只能在这个主题上找到这篇文章.在这篇文章中,回应的人说,这是有意义的处置.但是,如果我看一下情况和影响,我认为这是不对的.有人知道什么是正确的行动?
附加信息:在我看过的msdn示例中,它们不是Dispose或Close.
编辑
感谢Rick Sladkeys回答,我找到了解决方案:我分配StreamResourceInfo.Stream给了StreamSource-property BitmapImage.在msdn中写道:
如果要在创建BitmapImage后关闭流,请将CacheOption属性设置为BitmapCacheOption.OnLoad.默认的OnDemand缓存选项保留对流的访问,直到需要位图,并且清理由垃圾收集器处理.
这意味着,BitmapImage获取流的所有权.这就是为什么如果我手动关闭/处理流,内存分析器会显示错误:Bitmap将保存对流的引用(BitmapCacheOption OnDemand),因此只要BitmapImage有效,GC就不会释放它,但是流已经明确表示处置.在这个具体的例子中,处置是一个糟糕的想法.
为了完整性,我还在msdn中查看了TextRange.Load调用上述链接的示例.因为Load,相反,Load不占用所有权,因此必须在完成后关闭/处理流.
我的ftp服务器中有一个包含多个图像的文件夹。我正在尝试访问并在网页中显示这些图像,例如
<img src="ftp://my_ftp_ip_address/Images/imagename.jpg"/>
Run Code Online (Sandbox Code Playgroud)
但它要求输入FTP用户名和密码。我该如何实现?也可以使用Java来做同样的事情吗?
我正在解析维基百科的信息框,我注意到一些信息框有图像字段 - 这些字段包含维基百科藏在某处的图像文件的名称.但是它们只是包含文件的名称而不是实际的链接.
我检查了真实的实时信息框中图像的链接,链接似乎不是来自一个来源,但来源各不相同.我怎么能超链接到维基百科上的图像,因为我只有信息框条目中的图像名称.
我正在使用Viewbox创建一组图标,这些图标将动态绑定到WPF视图。
我将绑定到资源名称,并使用Converter将资源名称转换为ImageSource。
我知道如果资源是a Path时该怎么做,但是如何使用a来做呢Viewbox?
如果资源是Path,这就是我如何将资源名称转换为ImageSource:
public class ResourceNameToImageSourceConverter : BaseValueConverter {
protected override ImageSource Convert(string value, System.Globalization.CultureInfo culture) {
var resource = new ResourceDictionary();
resource.Source = new Uri("pack://application:,,,/MyAssembly;component/MyResourceFolder/ImageResources.xaml", UriKind.Absolute);
var path = resource[value] as Path;
if (path != null) {
var geometry = path.Data;
var geometryDrawing = new GeometryDrawing();
geometryDrawing.Geometry = geometry;
var drawingImage = new DrawingImage(geometryDrawing);
geometryDrawing.Brush = path.Fill;
geometryDrawing.Pen = new Pen();
drawingImage.Freeze();
return drawingImage; …
Run Code Online (Sandbox Code Playgroud)Run Code Online (Sandbox Code Playgroud) 我想知道如何将ImageSource对象(在我的例子中是图像元素的source属性)转换为WriteableBitmap.该WriteableBitmap(BitmapSource)构造函数无法在Windows 8地铁工作,所以我不能这样做.
我试图将ImageSource对象加载到流然后使用WriteableBitmap.SetSource(stream),但我无法弄清楚如何在流中加载图像.
InMemoryRandomAccessStream ras = new InMemoryRandomAccessStream();
BitmapEncoder enc = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, ras);
byte[] pixelArray = new byte[(uint)photoBox.Height * (uint)photoBox.Width * 4];
enc.SetPixelData(BitmapPixelFormat.Rgba8, BitmapAlphaMode.Straight,
(uint)photoBox.Width, (uint)photoBox.Height, 96, 96, pixelArray);
Run Code Online (Sandbox Code Playgroud)
我还添加了我在网上找到的帮助方法:
public Byte[] BufferFromImage(BitmapImage imageSource)
{
Stream stream = imageSource.StreamSource;
Byte[] buffer = null;
if (stream != null && stream.Length > 0)
{
using (BinaryReader br = new BinaryReader(stream))
{
buffer = br.ReadBytes((Int32)stream.Length);
}
}
return buffer;
}
Run Code Online (Sandbox Code Playgroud)
问题是BitmapImage …
c# imagesource writeablebitmap windows-runtime windows-store-apps
<Window x:Class="Project.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="100" Height="400">
<Window.Resources>
<Style x:Key="IconStyle" TargetType="{x:Type Image}">
<Setter Property="Source">
<Setter.Value>
<DrawingImage>
<DrawingImage.Drawing>
<GeometryDrawing Brush="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentControl}}, Path=Foreground}">
<GeometryDrawing.Geometry>
<PathGeometry Figures="M 0,0 0,10 10,5" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingImage.Drawing>
</DrawingImage>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<StackPanel>
<ContentControl Foreground="Red">
<Image Style="{StaticResource IconStyle}" />
</ContentControl>
<ContentControl Foreground="Blue">
<Image Style="{StaticResource IconStyle}" />
</ContentControl>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
此示例显示了两个图标。图标具有父 ContentControl 的颜色。它工作正常。
但输出显示绑定错误:
System.Windows.Data 错误:4:无法找到引用“RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ContentControl', AncestorLevel='1''的绑定源。BindingExpression:Path=前景;数据项=空;目标元素是“GeometryDrawing”(HashCode=8154127);目标属性是“画笔”(类型“画笔”)
为什么会出现这个错误?我该如何修复它或者我可以忽略它?
编辑
在这种情况下也会发生错误:
<Window x:Class="Project.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="100" Height="400">
<Window.Resources>
<Style x:Key="IconStyle" TargetType="{x:Type ContentControl}">
<Setter Property="Template"> …Run Code Online (Sandbox Code Playgroud) 我的资源目录中有4个图像到我的便携式项目中,我想直接将它们用于ImageSource(因为我需要绑定它).
ImageSource myImageSource = ImageSource.FromResource("resources.image.png");
Run Code Online (Sandbox Code Playgroud)
我试过这个,但它不认识路径.如何将我的图像用于ImageSource?
我正在使用一个在线商店来存储通过我们的应用程序上传的用户图像,并受 SSL 保护。上传工作一切顺利,因为我使用的是带有附加证书的 WebClient。但是,当我尝试使用 Xamarin.Forms.Image 组件(例如,源设置为“ https://blabla.com/upload/image123.jpg ”)时,图像无法在 Android 上加载。在 iOS 上,这是有效的,因为我有一个自定义的 NSUrlProtocol 来处理 SSL 连接。
var image = new Image();
//will use ImageLoaderSourceHandler
image.Source = "https://blabla.com/upload/image123.jpg";
Run Code Online (Sandbox Code Playgroud)
对于 WebClient,我将 X509Certificate2(私钥和密码)附加到 HttpWebRequest.ClientCertificates 并且它可以工作。但我不知道如何向 ImageLoaderSourceHandler 背后的任何加载机制提供该证书。
我如何才能在 Android 上实现此功能?
我正在使用 angular2-jwt 来授权请求。我有一个 get 请求,它从 API 中检索多个文档。
一个文档可以有多个图像,这些图像也需要使用授权请求来获取。所以显然直接用 with 调用它们是行不通的。
我按照这个例子: https //stackoverflow.com/a/40862839/909723
我有两个问题:
没有异步我得到:GET http://localhost:4200/[object%20Object] 404 (Not Found) 和异步我得到: Invalid argument '[object Object]' for pipe 'AsyncPipe' 我用'数据:图像/jpg;' 并且没有
部分模板
<md-card *ngFor="let document of documents">
<md-toolbar color="accent" *ngIf="getDocName(document)">
<span class="nowrap">{{getDocName(document)}}</span>
<span class="country-full-width"></span>
</md-toolbar>
<md-card-content>
<div *ngFor="let image of getImages(document)">
<img class="image" [src]="getImageSrc(image.image_id) | async" />
</div>
</md-card-content>
</md-card>
Run Code Online (Sandbox Code Playgroud)
我有一个使用 angular2-jwt 的服务 - AuthHttp
@Injectable()
export class ImageService {
constructor(public authHttp: AuthHttp, public http: Http, public sanitizer: DomSanitizer) {}
getImageSrc(id, type){ …Run Code Online (Sandbox Code Playgroud) imagesource ×10
c# ×3
wpf ×3
image ×2
xamarin ×2
angular ×1
asp.net-mvc ×1
data-binding ×1
default ×1
ftp ×1
html ×1
idisposable ×1
javascript ×1
mvvm ×1
performance ×1
php ×1
request ×1
ssl ×1
viewbox ×1
web-config ×1
webpage ×1
wikipedia ×1
xaml ×1