第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Image.Save(..)拋出GDI +異常,因?yàn)閮?nèi)存流已關(guān)閉

Image.Save(..)拋出GDI +異常,因?yàn)閮?nèi)存流已關(guān)閉

C#
胡說(shuō)叔叔 2019-07-26 15:14:47
Image.Save(..)拋出GDI +異常,因?yàn)閮?nèi)存流已關(guān)閉我有一些二進(jìn)制數(shù)據(jù),我想保存為圖像。當(dāng)我嘗試保存圖像時(shí),如果用于創(chuàng)建圖像的內(nèi)存流在保存之前關(guān)閉,則會(huì)引發(fā)異常。我這樣做的原因是因?yàn)槲艺趧?dòng)態(tài)創(chuàng)建圖像,因此我需要使用內(nèi)存流。這是代碼:[TestMethod]public void TestMethod1(){     // Grab the binary data.     byte[] data = File.ReadAllBytes("Chick.jpg");     // Read in the data but do not close, before using the stream.     Stream originalBinaryDataStream = new MemoryStream(data);     Bitmap image = new Bitmap(originalBinaryDataStream);     image.Save(@"c:\test.jpg");     originalBinaryDataStream.Dispose();     // Now lets use a nice dispose, etc...     Bitmap2 image2;     using (Stream originalBinaryDataStream2 = new MemoryStream(data))     {         image2 = new Bitmap(originalBinaryDataStream2);     }     image2.Save(@"C:\temp\pewpew.jpg"); // This throws the GDI+ exception.}有沒(méi)有人對(duì)如何在關(guān)閉流的情況下保存圖像有任何建議?我不能依賴(lài)開(kāi)發(fā)人員記住在保存圖像后關(guān)閉流。實(shí)際上,開(kāi)發(fā)人員沒(méi)有使用內(nèi)存流生成映像的IDEA(因?yàn)樗l(fā)生在其他地方的其他代碼中)。我真的很困惑:(
查看完整描述

3 回答

?
慕桂英546537

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超10個(gè)贊

GDI +中發(fā)生了一般錯(cuò)誤。 也可能是因?yàn)?strong>保存路徑不正確!我花了半天才注意到這一點(diǎn)。因此,請(qǐng)確保您已雙重檢查路徑以保存圖像。


查看完整回答
反對(duì) 回復(fù) 2019-07-26
?
藍(lán)山帝景

TA貢獻(xiàn)1843條經(jīng)驗(yàn) 獲得超7個(gè)贊

復(fù)制位圖。您必須在位圖的生命周期內(nèi)保持流打開(kāi)。

繪制圖像時(shí):System.Runtime.InteropServices.ExternalException:GDI中發(fā)生一般錯(cuò)誤

    public static Image ToImage(this byte[] bytes)
    {
        using (var stream = new MemoryStream(bytes))
        using (var image = Image.FromStream(stream, false, true))
        {
            return new Bitmap(image);
        }
    }

    [Test]
    public void ShouldCreateImageThatCanBeSavedWithoutOpenStream()
    {
        var imageBytes = File.ReadAllBytes("bitmap.bmp");

        var image = imageBytes.ToImage();

        image.Save("output.bmp");
    }


查看完整回答
反對(duì) 回復(fù) 2019-07-26
  • 3 回答
  • 0 關(guān)注
  • 869 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)