将字节数组[] []写入jpg

时间:2018-01-23 07:48:23

标签: c# bitmap

我希望在不使用Bitmap类的情况下执行以下代码 我不知道从哪里开始可以有人给我一些代码示例或示例来工作

public class PgmImage
{
    public int Width { get; set; }
    public int Height { get; set; }
    public int MaxVal { get; set; }
    public byte[][] Pixels { get; private set; }

    public PgmImage(int width, int height, int maxVal,
        byte[][] pixels)
    {
        this.Width = width;
        this.Height = height;
        this.MaxVal = maxVal;
        this.Pixels = pixels;
    }
}
    private static Bitmap MakeBitmap(PgmImage pgmImage, int mag)
    {
        int width = pgmImage.Width * mag;
        int height = pgmImage.Height * mag;
        Bitmap result = new Bitmap(width, height);
        Graphics gr = Graphics.FromImage(result);
        for (int i = 0; i < pgmImage.Height; ++i)
        {
            for (int j = 0; j < pgmImage.Width; ++j)
            {
                int pixelColor = pgmImage.Pixels[i][j];
                Color c = Color.FromArgb(pixelColor, pixelColor, pixelColor);
                SolidBrush sb = new SolidBrush(c);
                gr.FillRectangle(sb, j * mag, i * mag, mag, mag);
            }
        }
        return result;
    }

背后的原因是NetStandard没有使用Bitmap类

0 个答案:

没有答案