目前,我正在使用布伦丹*汤普金斯ImageQuantization dll。http://codebetter.com/blogs/brendan.tompkins/archive/2007/06/14/gif-image-color-quantizer-now-with-safe-goodness.aspx

但它没有运行中的介质的信任asp.net.

任何人都不会知道的像化图书馆,并运行中介质的信任?

更新 我不在乎如果解决方案是缓慢的。我只是需要一些东西,工作。

有帮助吗?

解决方案

您应该能够取代使用Marshal通过类似BinaryReader在底层流的明确阅读的代码。这可能是因为速度较慢,您必须阅读流完全进入你的管理内存或寻求到它,而不是依靠拷贝已经在非托管内存是快速访问,但基本上是你唯一的选择。

您根本就不能去探洞到非托管内存从一个中等信任背景下,即使只执行读取操作。

说完看着链接的代码有你不允许做这样的事情的理由。对于初学者来说他忽略的IntPtr的64位/ 32位的方面!

他的使用上具有任意内存不受约束的读访问完全预测的基本BitmapData类,这是从来没有下中等信任发生。结果 他的基本功能甲显著重写将被要求要么使用位图的直接(用慢GetPixel呼叫)或经由常规流的API直接读取数据,拖放到一个数组(一个或多个),然后解析出来自己。这些都不很可能是愉快的。前者会更慢(我希望由于每个像素读高开销量级),以后少慢(但仍慢),但在改写图像数据的低层次的解析方面有更多的相关努力

下面是一个粗略的指南,你需要改变基于当前的代码是什么:

这Quantizer.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类将处理所有的你。

Bitmap.SetPixel()将处理第二遍。请注意,这是港口事情最简单的方法,但绝对不是中等信任环境中做到这一点的最快方式。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top