I made migration from System.Drawing to SkiSharp and have method to fills a bitmap with 8 bits
The working time with my picture takes 50 seconds, when using System.Drawing was much faster
How can I speed up the running time of my method?
<code>private void FillBitmap8Bit(SKBitmap bmp, int row, RGBValues[] input)
{
bool setRed = (_params.Format == FrameFormat.Gray || _params.Format == FrameFormat.RGB || _params.Format == FrameFormat.Red);
bool setGreen = (_params.Format == FrameFormat.Gray || _params.Format == FrameFormat.RGB || _params.Format == FrameFormat.Green);
bool setBlue = (_params.Format == FrameFormat.Gray || _params.Format == FrameFormat.RGB || _params.Format == FrameFormat.Blue);
//bool setAlpha = (bmp.AlphaType & SKAlphaType.Premul) != 0;
//The pixel data contains alpha values that are not premultiplied.
for (int i = 0; i < _params.PixelsPerLine; i++)
{
var pixelColor = bmp.GetPixel(i, row);
if (setRed)
pixelColor = pixelColor.WithRed((byte)(input[i].R >> 8));
if (setGreen)
pixelColor = pixelColor.WithGreen((byte)(input[i].G >> 8));
if (setBlue)
pixelColor = pixelColor.WithBlue((byte)(input[i].B >> 8));
// Set the new pixel color
bmp.SetPixel(i, row, pixelColor);
}
}
</code>
<code>private void FillBitmap8Bit(SKBitmap bmp, int row, RGBValues[] input)
{
bool setRed = (_params.Format == FrameFormat.Gray || _params.Format == FrameFormat.RGB || _params.Format == FrameFormat.Red);
bool setGreen = (_params.Format == FrameFormat.Gray || _params.Format == FrameFormat.RGB || _params.Format == FrameFormat.Green);
bool setBlue = (_params.Format == FrameFormat.Gray || _params.Format == FrameFormat.RGB || _params.Format == FrameFormat.Blue);
//bool setAlpha = (bmp.AlphaType & SKAlphaType.Premul) != 0;
//The pixel data contains alpha values that are not premultiplied.
for (int i = 0; i < _params.PixelsPerLine; i++)
{
var pixelColor = bmp.GetPixel(i, row);
if (setRed)
pixelColor = pixelColor.WithRed((byte)(input[i].R >> 8));
if (setGreen)
pixelColor = pixelColor.WithGreen((byte)(input[i].G >> 8));
if (setBlue)
pixelColor = pixelColor.WithBlue((byte)(input[i].B >> 8));
// Set the new pixel color
bmp.SetPixel(i, row, pixelColor);
}
}
</code>
private void FillBitmap8Bit(SKBitmap bmp, int row, RGBValues[] input)
{
bool setRed = (_params.Format == FrameFormat.Gray || _params.Format == FrameFormat.RGB || _params.Format == FrameFormat.Red);
bool setGreen = (_params.Format == FrameFormat.Gray || _params.Format == FrameFormat.RGB || _params.Format == FrameFormat.Green);
bool setBlue = (_params.Format == FrameFormat.Gray || _params.Format == FrameFormat.RGB || _params.Format == FrameFormat.Blue);
//bool setAlpha = (bmp.AlphaType & SKAlphaType.Premul) != 0;
//The pixel data contains alpha values that are not premultiplied.
for (int i = 0; i < _params.PixelsPerLine; i++)
{
var pixelColor = bmp.GetPixel(i, row);
if (setRed)
pixelColor = pixelColor.WithRed((byte)(input[i].R >> 8));
if (setGreen)
pixelColor = pixelColor.WithGreen((byte)(input[i].G >> 8));
if (setBlue)
pixelColor = pixelColor.WithBlue((byte)(input[i].B >> 8));
// Set the new pixel color
bmp.SetPixel(i, row, pixelColor);
}
}
speed up the running time of method
New contributor
Foitelija is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.