Имеется файл с картинкой формата Format8bppIndexed. Нужно загрузить его и преобразовать в формат Format32bppArgb.
Сейчас делаю так:
image_ — изображение формата Format8bppIndexed
image — изображение формата Format32bppArgb
Bitmap image_ = new Bitmap(FileName);
Bitmap image = new Bitmap(image_.Width, image_.Height, PixelFormat.Format32bppRgb);
BitmapData bmpData_ = image_.LockBits(new Rectangle(0, 0, image_.Width, image_.Height),
ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
BitmapData bmpData32 = image.LockBits(new Rectangle(0, 0, image_.Width, image_.Height),
ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
IntPtr bmpPtr = bmpData_.Scan0;
IntPtr bmpPtr32 = bmpData32.Scan0;
unsafe
{
byte * pBits = (byte * ) bmpPtr;
byte * pBits32 = (byte * ) bmpPtr32;
byte _color;
for(int i=0; i<image_.Height; ++i)
for(int k=0; k<image_.Width; ++k)
{
_color = pBits[i * image_.Width + k];
pBits32[4* (i * image_.Width + k)] = _color;
pBits32[4* (i * image_.Width + k) + 1] = _color;
pBits32[4* (i * image_.Width + k) + 2] = _color;
pBits32[4* (i * image_.Width + k) + 3] = 255;
}
}
image_.UnlockBits(bmpData_);
image.UnlockBits(bmpData32);
Однако это все работает очень долго. Как это все оптимизировать?
17.01.07 12:44: Перенесено модератором из '.NET' — TK