2014-02-12 42 views
0

如何將picturebox中的結果thresolded圖像轉換爲8bbp像素格式? 我試過這段代碼,但它不工作?如何將picturebox中的結果thresolded圖像轉換爲8bbp像素格式

Bitmap orig = new Bitmap(thresholded); 
      Bitmap clone = new Bitmap(width , height , System.Drawing.Imaging.PixelFormat.Format8bppIndexed); 
      using (Graphics gr = Graphics.FromImage(clone)) 
      { 
       gr.DrawImage(orig, new Rectangle(0, 0, width, height)); 
      } 

錯誤是「圖形對象無法從具有索引像素格式的圖像創建」。

我需要你的幫助。

+0

錯誤是「例外是未處理」 –

+0

你需要更聰明的代碼,知道如何建立一個只有256種顏色的調色板仍然可以得到體面的結果。毫無意義的今天順便說一句,這停止了20年前的事情。有傳言說FreeImage有可靠的轉換器。 –

回答

0

快速谷歌生成此答案

http://social.msdn.microsoft.com/Forums/vstudio/en-US/edd45c87-366c-4af8-a6fe-8ba9b1ffb002/a-graphics-object-cannot-be-created-from-an-image-that-has-an-indexed-pixel-format?forum=csharpgeneral

的索引圖像是用調色的圖像。 GDI +不支持繪製索引圖像。繪製非索引圖像的索引圖像,然後繪製非索引圖片上的文字:

Bitmap newBitmap = new Bitmap(bm.Width, bm.Height); 
    Graphics graphics = Graphics.FromImage(newBitmap); 
    graphics.DrawImage(bm, 0, 0); 
+0

我嘗試了新代碼,但它不起作用 –

+0

問題是如何將picturebox中的結果圖像轉換爲8bpp? –

相關問題