我正在尝试将a转换Bitmap (SystemIcons.Question)为a,BitmapImage因此我可以在WPF图像控件中使用它.
我有以下方法将其转换为a BitmapSource,但它返回一个InteropBitmapImage,现在的问题是如何将其转换为BitmapImage.直接演员似乎不起作用.
有谁知道怎么做?
码:
public BitmapSource ConvertToBitmapSource()
{
int width = SystemIcons.Question.Width;
int height = SystemIcons.Question.Height;
object a = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(SystemIcons.Question.ToBitmap().GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(width, height));
return (BitmapSource)a;
}
Run Code Online (Sandbox Code Playgroud)
返回BitmapImage的属性:(绑定到我的图像控件)
public BitmapImage QuestionIcon
{
get
{
return (BitmapImage)ConvertToBitmapSource();
}
}
Run Code Online (Sandbox Code Playgroud) 我发现设置RequestCachePolicy属性对于BitmapImage将Images Source设置为此实例时如何下载位图没有影响BitmapImage.
例如,如果我设置RequestCachePolicy为CacheOnly,我预计不会发生任何互联网流量 - 只应从缓存中检索指定的图像.但相反,我看到要求服务器下载图像的请求:
source = new BitmapImage(bmi.UriSource,
new RequestCachePolicy(RequestCacheLevel.CacheOnly));
// An image gets downloaded!
Run Code Online (Sandbox Code Playgroud)
如果我设置静态DefaultCachePolicy属性HttpWebRequest,那么我的应用程序行为会以我期望的方式发生变化.即,当它被设置为时CacheOnly,不会发生网络流量.
为什么RequestCachePolicy房产BitmapImage没有我期望的效果?
我有一个 14406x9606 像素的 8 位 tiff,当通过 BitmapImage 加载时会抛出 System.OutOfMemoryException。作为全深度位图,其大小约为 400 兆。有没有办法将图像划分为更易于管理的块?我已经尝试使用 DecodePixelHeight 以较低的分辨率加载它并且这有效,但是每当缩放级别发生变化时我都需要重新加载。是否有任何既定工具可以在不同的缩放级别处理 WPF 中的非常大的图像?
我想把我BitmapImage变成一个System.Drawing.Image?
这是我的BitmapImage:
BitmapImage bmi = new BitmapImage(new Uri(someString, UriKind.Absolute));
Run Code Online (Sandbox Code Playgroud)
现在,我将如何创建一个System.Drawing.Image来自我的bmi?
我正在创建一个包含任意值的字节数组,并希望将其转换为BitmapImage.
bi = new BitmapImage();
using (MemoryStream stream = new MemoryStream(data))
{
try
{
bi.BeginInit();
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.StreamSource = stream;
bi.DecodePixelWidth = width;
bi.EndInit();
}
catch (Exception ex)
{
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码一直给我一个NotSupportedException.我怎么能从任何字节数组创建一个BitmapSource?
我正在编写一个应用程序,要求我将大图像拆分成小图块,其中每个图块基本上是原始图像的裁剪版本.
目前我的拆分操作看起来像这样
tile.Image = new BitmapImage();
tile.Image.BeginInit();
tile.Image.UriSource = OriginalImage.UriSource;
tile.Image.SourceRect = new Int32Rect(x * tileWidth + x, y * tileHeight, tileWidth, tileHeight);
tile.Image.EndInit();
Run Code Online (Sandbox Code Playgroud)
直觉上,我认为这将基本上创建原始图像的"参考",并且只显示为图像的子矩形.然而,我的分割操作执行速度慢导致我认为这实际上是复制原始图像的源矩形,对于大图像来说这是非常慢的(当分割一个体面时有一个明显的3-4秒暂停大小图片).
我环顾四周但却找不到一种方法来绘制位图作为大图像的子矩形,而无需复制任何数据.有什么建议?
我最近安装了Windows 8.1来尝试,我的宠物项目正在崩溃(同样的二进制文件在一台Win7和两台Win8机器上工作正常).
在BitmapImage.EndInit中抛出OutOfMemoryException:
public static BitmapImage GetResourceImage(string resourcePath, int decodePixelWidth = 0, int decodePixelHeight = 0)
{
var image = new BitmapImage();
var moduleName = Assembly.GetExecutingAssembly().GetName().Name;
var resourceLocation = string.Format("pack://application:,,,/{0};component/Resources/{1}", moduleName, resourcePath);
image.BeginInit();
image.UriSource = new Uri(resourceLocation);
image.DecodePixelWidth = decodePixelWidth;
image.DecodePixelHeight = decodePixelHeight;
image.EndInit();
image.Freeze();
return image;
}
Run Code Online (Sandbox Code Playgroud)
据我通过谷歌搜索了解,它与GDI内部有关,但我找不到修复或解决方法.任何想法(除了使用一些其他机制来解码和/或调整图像大小 - 我只需要原始像素数据)?
可在此处找到完整的项目源代码(链接指向相关文件):https://code.google.com/p/lander-net/source/browse/trunk/csharp/LanderNet/Util/BitmapUtils.cs
更新: 我尝试使用TransformedBitmap进行大小调整,它失败并出现相同的异常.
我有一个ListView包含一些电子邮件的Android .其中一些有联系人缩略图,而有些则没有.对于未知的联系人缩略图,我想创建一个位图,其中包含相应电子邮件ID的首字母.我怎样才能做到这一点?我见过一些使用这种技术的Android应用程序来显示这样的联系人缩略图:

首先,我使用以下代码:
ImageView iv=(ImageView)findViewById(R.id.imageView1);
TextView view = (TextView)findViewById(R.id.textView1);
Bitmap b=Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
view.draw(c);
iv.setImageBitmap(b);
Run Code Online (Sandbox Code Playgroud)
TextView包含一个简单的字符串.不幸的是,它不起作用.有人可以给我一些指示吗?非常感谢你的帮助!
android thumbnails bitmapimage android-layout android-imageview
我正在尝试在我的应用中添加对平板电脑的支持,并遇到由此行代码抛出的IllegalArgumentException:
marker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.arrow_green_10by19))
Run Code Online (Sandbox Code Playgroud)
方法.fromResource可以从图像文件(png)中使用R.drawable.arrow_green_10by19,但是当用矢量文件arrow_green_10by19.xml(在Android Studio IDE中渲染得很好)替换png时,它会生成如上所述的运行时.
有人知道如何在BitmapDescriptorFactory中实现矢量资源并可以帮助我吗?
谢谢.
如何在UWP中将BitmapImage对象转换为字节数组?在.Net中很容易实现,即使在以前的WinRT版本中,看起来遍布互联网但没有成功,其中一个解决方案是使用WriteableBitmap这个答案中提到的类似,但在当前版本的UWP中,构建一个WriteableBitmap一个BitmapImage是不可能的,任何解决方法?
bitmapimage ×10
c# ×5
wpf ×5
android ×2
image ×2
bitmapsource ×1
c#-4.0 ×1
crop ×1
performance ×1
svg ×1
thumbnails ×1
tiff ×1
windows-8.1 ×1
winrt-xaml ×1
xml-drawable ×1