- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我需要将图像转换为位图。
最初 gif 以字节形式读入,然后转换为图像。
但是当我尝试将图像转换为位图时,我的图片框中显示的图形以前是白色的,但现在却变成了黑色背景。
代码如下:
var image = (System.Drawing.Image)value;
// Winforms Image we want to get the WPF Image from...
var bitmap = new System.Windows.Media.Imaging.BitmapImage();
bitmap.BeginInit();
MemoryStream memoryStream = new MemoryStream();
// Save to a memory stream...
image.Save(memoryStream, ImageFormat.Bmp);
// Rewind the stream...
memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
bitmap.StreamSource = memoryStream;
bitmap.EndInit();
return bitmap;
谁能解释一下为什么背景变黑了,我该如何阻止它。
谢谢
最佳答案
不要另存为位图文件。文件格式不支持透明度,因此图像将在不透明的情况下保存。
您可以改用 PNG 文件格式。这将保持透明度。
如果你真的需要它使用位图文件格式,你必须先让它不透明。新建一个相同大小的位图,使用Graphics.FromImage
方法得到一个图形对象绘制在图像上,使用Clear
方法填充背景颜色,使用 DrawImage
方法在背景上绘制图像,然后保存该位图。
关于c# - 将图像转换为位图会使背景变黑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4067448/
我想知道为什么当我将选定的属性设置为 ON 时,这段代码会给我黑色的 UITableViewCells。如果我这样做,单元格的内容就会完全变黑,我不知道为什么。 这是代码 // // TableVi
我有一个从内容管道加载的 Texture2D。这工作正常,但一旦我尝试在完全不同的 Texture2D 上使用 SetData,我游戏中的所有纹理就会完全变黑: 这是在我的 HUDMeter 类中,我
首先,当我调用 presentViewController:navigationController 时,它会显示正常的绿色导航栏。但是在动画完成后导航栏变得有点暗。 if(!userPageView
我嵌入了一个 UITabBarController 在 UINavigationController 中。 UITabBarController 包含 3 个不同的选项卡,导致 3 个不同的 UIVi
你好,我有tableview,我在其中填充来自网络服务的数据。我首先在表格 View 上显示事件指示器,直到数据来自服务器。问题是,当旋转器移动时, table 会变黑,直到数据出现并且 table
我做了一个简单的自动答题器,但是当我运行它时屏幕变黑,所以我无法停止它等等。我不知道我做错了什么。我想也许我必须集中注意力,但我不确定。代码: import java.awt.AWTException
出于某种原因,如果您突出显示文本区域文本,背景会变成黑色,从而使文本不可读,同样当我选择底部的单选按钮(见附图)时,整个文本区域会再次变黑使文本不可读!有人知道为什么要这样做吗? 这是我的文本区域的代
我在这里看到了这个 SO 问题:Can I tint (black) a UIKeyboard? If so, how? ,其中最佳答案表明您可以进行破解,但这样做可能会使您的应用程序被 Apple
当焦点位于另一个窗口时,我不想让我的主 JFrame 变暗。这是游戏 Football Manager 2012 中的示例。首先选择了主窗口,看起来应该如此,然后在加载时,它变得更暗且无法选择。我不想
我在玩 clone()当我发现一个奇怪的行为时从 jQuery 调用函数。 此代码重现了该问题。第一个 div 包含一个 SVG。两个按钮允许将 SVG 克隆到第二个 div 中。尝试两次会使圆圈变黑
我试图通过创建颜色列表,然后使用 for 循环循环它们,然后重新绘制来在 jframe 中制作闪烁的灯光。但是当我在代码中添加一个 for 循环时,整个事情就出错了,我得到一个黑屏并且它变得不稳定。为
从不同选项卡返回 View Controller 时出现黑屏。 我有以下流程: 带有 5 个选项卡的选项卡栏。 一个名为 Points 的 View Controller ,其中包含一个名为“Rewa
我有一个空 Canvas ,如果我将其渲染为质量为 0.5 的 jpeg,则 jpeg 将是黑色,为什么? 我的代码: var url = canvas.toDataURL('image/jpeg',
我在 iOS 8 中使用 UISearchController,在选项卡 Controller 中嵌入的 View Controller 的 viewDidLoad 中使用以下初始化 _search
当调用 setTextColor 时,TextView 变黑或接近黑色。不知道为什么。任何帮助将不胜感激。 目前正在使用 holo.light。 如下设置我的TextView 当我尝试调用
我正在使用我创建的 UIImageView 的子类,我在其中将其 tintColor 设置为白色: class UIIconView : UIImageView { override init
当我离开带有 ScrollView 的 Activity 然后返回到它时,ScrollView 变黑。发射时,颜色是正确的。就在我离开并返回时,它变黑了。我尝试设置 ScrollView 和内部 Li
我正在制作一个应用程序,它在底部有一堆按钮,在顶部有一堆 ViewStub。所有按钮都指向一个监听器,该监听器在按钮 id 之间切换,以决定扩充哪个 stub 。因此,如果单击按钮 1,则会撤消之前的
使用下面的代码(在 viewDidLoad 中),当我第一次从另一个 View 切换到这个静态相机 View (按下按钮)时,一切正常。然后我派出一个代表,让这个 View 从之前的 View 中消失
我正在使用 Swift 开发我的第一个 iOS 应用程序,我遇到一个问题,当我向我的元素添加约束时,我的一个标签栏 View 在 iOS 模拟器 (iPhone 6) 中变成黑色。我发现我可以有时通过
我是一名优秀的程序员,十分优秀!