문제

나는 현재 사용하여 브렌든 톰킨스 ImageQuantization dll.http://codebetter.com/blogs/brendan.tompkins/archive/2007/06/14/gif-image-color-quantizer-now-with-safe-goodness.aspx

하지만 그렇지 않을 실행에서 매체에서 신뢰 asp.net.

는 누군가의 이미지 양자화된 라이브러리는 실행에서 매체를 신뢰하는가?

업데이트 나는 걱정하지 않는 경우 솔루션에 속도가 느립니다.나는 단지 무언가가 필요 작품이다.

도움이 되었습니까?

해결책

할 수 있어야 대체 코드는 원수를 사용하여 명시적으로 읽고의 근본적인 스트림을 통해 무언가가 다음과 같 BinaryReader.이 느려질 수 있습해야 하기 때문에 읽고 스트림으로 관리되는 메모리 또는 추구으로 그것에 의존하기보다는 복사본 이미에서 관리되지 않는 기억되고 빠르게 액세스할 수 있지만 근본적으로 귀하의 유일한 옵션을 제공합니다.

당신은 단순히 갈 수 없습니다 동굴 탐험으로 관리되지 않는 메모리에서 매체 컨텍스트를 신뢰하는 경우에도,수행 읽는 작업입니다.

여러 가지에 연결된 코드가 있는 이유를 허용하지 않는 이런 종류의 것입니다.우선 그는 무시 64/32 비트의 측면 IntPtr!

근본적인 비트맵 이미지를 클래스를 사용하고 완전하게 입각에는 자유롭게 읽을 액세스하는 임의의 메모리,이것은 결코에서 일어나고 있는 일 중 신뢰합니다.
상당의 다시 작성의 기본 기능이 필요하거나 사용이트맵 바로(느린 GetPixel 출)또는 데이터를 읽을 통해 직접 기존의 스트림 api 떨어지고,그것은 배열로(s)그리고 분석이 그것입니다.도 이러한될 가능성이 높은 쾌적하다.전 될 것입니다 훨씬 느리게(I 대 크기 순으로 높은 오버헤드 픽셀당 읽어),나중에 미만 느립니다(하지만 여전히 느리게)하지만 훨씬 더 관련된 노력의 관점에서 다시 쓰는 낮은 수준으로 구문 분석의 이미지 데이터입니다.

여기에의 거친 가이드 당신은 당신이 필요에 따라 변경 현재 코드:

에서 양자화.cs

public Bitmap Quantize(Image source)
{
    // Get the size of the source image
    int height = source.Height;
    int width = source.Width;
    // And construct a rectangle from these dimensions
    Rectangle bounds = new Rectangle(0, 0, width, height);
    // First off take a 32bpp copy of the image
    Bitmap copy = new Bitmap(width, height, PixelFormat.Format32bppArgb);
    // And construct an 8bpp version
    Bitmap output = new Bitmap(width, height, PixelFormat.Format8bppIndexed);
    // Now lock the bitmap into memory
    using (Graphics g = Graphics.FromImage(copy))
    {
        g.PageUnit = GraphicsUnit.Pixel;
        // Draw the source image onto the copy bitmap,
        // which will effect a widening as appropriate.
            g.DrawImage(source, bounds);
    }

    //!! BEGIN CHANGES - no locking here
    //!! simply use copy not a pointer to it
    //!! you could also simply write directly to a buffer then make the final immage in one go but I don't bother here

    // Call the FirstPass function if not a single pass algorithm.
    // For something like an octree quantizer, this will run through
    // all image pixels, build a data structure, and create a palette.
    if (!_singlePass)
        FirstPass(copy, width, height);

    // Then set the color palette on the output bitmap. I'm passing in the current palette 
    // as there's no way to construct a new, empty palette.
    output.Palette = GetPalette(output.Palette);
    // Then call the second pass which actually does the conversion
    SecondPass(copy, output, width, height, bounds);
    //!! END CHANGES
    // Last but not least, return the output bitmap
    return output;
}

//!! Completely changed, note that I assume all the code is changed to just use Color rather than Color32
protected  virtual void FirstPass(Bitmap source, int width, int height)
{
    // Loop through each row
    for (int row = 0; row < height; row++)
    {
        // And loop through each column
        for (int col = 0; col < width; col++)
        {            
            InitialQuantizePixel(source.GetPixel(col, row)); 
        }   // Now I have the pixel, call the FirstPassQuantize function...
    }
}

당신이 거의 동일에 다른 기능이 있습니다.이를 제거를 위한 모든 필요 Color32,비트맵 클래스가 다루는 모든 것을 당신을 위해.

Bitmap.SetPixel() 다룰 것이 두 번째 전달합니다.이는 가장 쉬운 방법 포트지 절대적으로 작업을 수행하는 가장 빠른 방법은 내에 보통 신뢰 environment.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top