久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

將圖像轉(zhuǎn)換為位圖會使背景變黑

Converting Image to bitmap turns background black(將圖像轉(zhuǎn)換為位圖會使背景變黑)
本文介紹了將圖像轉(zhuǎn)換為位圖會使背景變黑的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我需要將圖像轉(zhuǎn)換為位圖.

I need to convert an Image to a bitmap.

最初以字節(jié)形式讀取 gif,然后將其轉(zhuǎn)換為圖像.

initially a gif was read in as bytes and then converted to an Image.

但是當(dāng)我嘗試將圖像轉(zhuǎn)換為位圖時,顯示在我的圖片框中的圖形在以前是白色時變成了黑色背景.

But when I try convert the image to a bit map, the graphic displaying in my picturebox has a black background when it used to be white.

代碼如下:

    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;

有人可以解釋為什么背景變黑以及我如何阻止它這樣做.

Can some one explain why the background is going black and how i can stop it doing this.

謝謝

推薦答案

不要保存為位圖文件.文件格式不支持透明,保存時圖片不透明.

Don't save as a bitmap file. The file format doesn't support transparency, so the image will be saved without transparency.

您可以改用 PNG 文件格式.這將保持透明度.

You can use the PNG file format instead. That will preserve the transparency.

如果你真的需要它使用位圖文件格式,你必須先讓它不透明.新建一個相同大小的位圖,使用Graphics.FromImage方法獲取一個圖形對象繪制在圖片上,使用Clear方法填充背景顏色,使用 DrawImage 方法在背景上繪制圖像,然后保存該位圖.

If you really need it to use the bitmap file format, you have to make it non-transparent first. Create a new bitmap with the same size, use the Graphics.FromImage method to get a graphics object to draw on the image, use the Clear method to fill it with the background color that you want, use the DrawImage method to draw your image on top of the background, and then save that bitmap.

這篇關(guān)于將圖像轉(zhuǎn)換為位圖會使背景變黑的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Right-click on a Listbox in a Silverlight 4 app(右鍵單擊 Silverlight 4 應(yīng)用程序中的列表框)
WPF c# webbrowser scrolls over top menu(WPF c# webbrowser 在頂部菜單上滾動)
C# Console app - How do I make an interactive menu?(C# 控制臺應(yīng)用程序 - 如何制作交互式菜單?)
How to avoid duplicate form creation in .NET Windows Forms?(如何避免在 .NET Windows Forms 中創(chuàng)建重復(fù)的表單?)
UI Automation Control Desktop Application and Click on Menu Strip(UI自動化控制桌面應(yīng)用程序并單擊菜單條)
Removing thin border around the menuitems(刪除菜單項周圍的細(xì)邊框)
主站蜘蛛池模板: 日中文字幕在线 | 久久999| 狠狠综合久久av一区二区小说 | 中文字幕第一页在线 | 欧美激情亚洲天堂 | 久久久久国产精品午夜一区 | 亚洲欧美日韩精品久久亚洲区 | 一区免费| 欧美一区二区另类 | 久久99精品久久久久蜜桃tv | 天天干天天干 | 久久精品亚洲精品国产欧美 | 搞av.com| 亚洲欧美一区二区三区国产精品 | 精品在线观看一区二区 | 狠狠插狠狠操 | 亚洲 中文 欧美 日韩 在线观看 | 国产精品永久久久久久久www | 九九天堂网 | 国产97久久 | 日韩精品一区二区三区免费观看 | 九九热免费在线观看 | 欧美理论片在线观看 | 欧美日韩国产一区二区三区 | 久草成人网 | 久草视| 国产精品美女久久久久久不卡 | 国产成人免费视频网站高清观看视频 | 草草草影院 | 精品免费视频 | 久久精品亚洲精品国产欧美 | 国产精品1区2区3区 一区中文字幕 | 中文字幕一区二区视频 | 国产高清免费视频 | 欧美亚洲国产一区二区三区 | 日韩精品在线免费 | 国产在线观看一区二区三区 | 天天狠狠| 日韩欧美国产精品一区二区 | 羞羞色影院 | 欧美四虎|