2014-01-08 2 views
1

색 변환을 수행 할 비트 맵이 있습니다. 나는 픽셀의 새로운 배열을 가지고 있지만 나는 그 이미지비트 맵 픽셀 배열을 새 비트 맵으로 저장

public static void TestProcessBitmap(string inputFile, string outputFile) 
    { 
     Bitmap bitmap = new Bitmap(inputFile); 
     Bitmap formatted = bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.PixelFormat.Format8bppIndexed); 

     byte[] pixels = BitmapToPixelArray(formatted); 

     pixels = Process8Bits(pixels, System.Windows.Media.Colors.Red); 

     Bitmap output = new Bitmap(pixels); //something like this 
    } 

으로 디스크에 다시 저장하는 방법을 잘 모르겠어요 어떻게 다음 디스크에 비트 맵으로 새 픽셀을 저장할 수 있습니까?

+1

비트 맵을 적절히 처리해야합니다. http://stackoverflow.com/questions/5838608/net-and-bitmap-not-automatically-disposed-by-gc-when-there-is-no-memory-left – geedubb

답변

2

바이트를 Bitmap 객체로 다시로드 한 후에 Bitmap.Save() 메서드를 사용할 수 있다고 생각합니다. This post은 어떻게하는지에 대한 통찰력을 줄 수 있습니다. Bitmap.Save()를 사용하는 동안 당신은 단지 경로를 지정하면

According to this MSDN document

,

엔코더 이미지의 파일 형식이없는 경우는, 휴대용 네트워크 그래픽 (PNG) 인코더를 사용한다.

+0

이 경우 메모리에있는 스트림은 다음과 같습니다. 파일 자체가 아닌 비트 맵의 ​​실제 픽셀 수 – jimmyjambles

1

MemoryStream을 사용하여 바이트 배열을 비트 맵으로 변환 한 다음 Image.FromStream 메서드에 입력 할 수 있습니다. 이것으로 당신의 예가 될 것입니다 ..

public static void TestProcessBitmap(string inputFile, string outputFile) 
{ 
    Bitmap bitmap = new Bitmap(inputFile); 
    Bitmap formatted = bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.PixelFormat.Format8bppIndexed); 

    byte[] pixels = BitmapToPixelArray(formatted); 

    pixels = Process8Bits(pixels, System.Windows.Media.Colors.Red); 

    using (MemoryStream ms = new MemoryStream(pixels)) 
    { 
     Bitmap output = (Bitmap)Image.FromStream(ms); 
    } 
} 
+0

+1 - 제가 언급 한 게시물보다 간단한 접근 방법으로 보입니다. – OnoSendai

+0

필자는 필연적으로 이것이 더 단순한 접근법이지만 다른 목적을 달성하고 있다는 것을 확신 할 수 없다. 이 대답은 단순히 바이트 배열에서 비트 맵 객체를 생성하는 반면 Bitmap.Save()는 비트 맵을 가져 와서 파일이나 스트림에 저장합니다. –

+0

나를 잘못 이해하지 마라. 나는 더 간단하다고 생각한다. 그리고 나는 이것을 의미합니다 - http://stackoverflow.com/questions/6782489/create-bitmap-from-a-byte-array-of-pixel-data – OnoSendai

관련 문제