C# 手工绘制图像并将其保存为数组?

C# 手工绘制图像并将其保存为数组?,c#,arrays,image,C#,Arrays,Image,问题:我应该使用什么程序/文件格式? 我想创建一个图像(逐像素手工绘制),并将其导出到文本文件,格式为整数的伪数组,如下所示: 16 8 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 0

问题:我应该使用什么程序/文件格式?

我想创建一个图像(逐像素手工绘制),并将其导出到文本文件,格式为整数的伪数组,如下所示:

16  8

0   0   0   0   0   0   0   0   1   1   1   1   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   2   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   3   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   4   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   9   0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   10  0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   11  0   0   0   0
0   0   0   0   0   0   0   0   0   0   0   12  0   0   256 0
我希望每个数字都代表唯一的颜色(事实上,只要绘图程序(越简单越好-MS-Paint)本身可以读取它,并且我可以将它与其他颜色区分开来,就不必管它是什么颜色了)。最终,我希望能够使用外部程序快速绘制图像,并在代码中使用这些导出的数据。有人能给我指一下正确的方向吗

我尝试使用GIMP将图像导出到.c,但结果如下:

/* GIMP RGB C-Source image dump (Bez nazwy.c) */

static const struct {
  guint      width;
  guint      height;
  guint      bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */ 
  guint8     pixel_data[64 * 64 * 2 + 1];
} gimp_image = {
  64, 64, 2,
  "\377\377\0\0\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
  "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
  "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
  "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
  "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"
  "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377"...
虽然接近要点,但这并不完全是我所期望的

在这里,我看到了其他可能的解决方案:简单地绘制bmp图像,并尝试在实际代码中将其转换为整数数组(C#)。但我想避免这种情况,除非有一些简单快捷的方法/方便的库来做到这一点

或者你们中的一些人知道任何在线转换器,它可以接受.bmp并返回一个整数数组?

\35;包括“ui\u mainwindow.h”
#include "ui_mainwindow.h"
#include <QString>

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;

void generate(Ui::MainWindow* ui)
{
    if (ui->pic_label->pixmap() != 0)
    {
        int cap = 1024 * 4;
        int ct = 32;    //color tolerance
        //int number_of_colors_third = 256 / color_tolerance;//=256/32=8
        int *uncompressedcolortable = new int[256*256*256];
        for (int k=0; k<256; k++){
            for (int j=0; j<256; j++){
                for (int i=0; i< 256; i++){
                    uncompressedcolortable[k*256*256+j*256+i] = k*1000000+j*1000+i;
                }
            }
        }
        int width = ui->pic_label->pixmap()->width();
        int height = ui->pic_label->pixmap()->height();
//        int tiles = width * height;

        if ( (width > cap || height > cap) && !(ui->actionSurpass_sanity_check->isChecked())){
            ui->label->setText("File is too big to generate map. Check menu option if you want to process it anyway.");
            return;
        }

        QImage image = ui->pic_label->pixmap()->toImage();
        ui->lcdRED->setPalette(Qt::red);
        ui->lcdGREEN->setPalette(Qt::green);
        ui->lcdBLUE->setPalette(Qt::blue);
        ui->progressBar->setMaximum(height);
        QColor pixel_color;
        ofstream outfile ("C:/Users/Niewzruszony/Desktop/map.map");
        outfile << width << " " << height << std::endl;

        for (int j = 0; j < height; j++ )
        {
            outfile << std::endl;
            for (int i = 0; i < width; i++)
            {
                pixel_color = image.pixelColor(i,j);
                outfile << uncompressedcolortable[pixel_color.red()*256*256 + pixel_color.green()*256 + pixel_color.blue()];
                if(i != width-1) outfile << "\t";
                ui->lcdRED->display(QString::fromStdString(to_string( pixel_color.red())));
                ui->lcdGREEN->display(QString::fromStdString(to_string( pixel_color.green())));
                ui->lcdBLUE->display(QString::fromStdString(to_string( pixel_color.blue())));
            }
            ui->progressBar->setValue(j+1);
        }

        ui->lcdRED->setPalette(Qt::lightGray);
        ui->lcdGREEN->setPalette(Qt::lightGray);
        ui->lcdBLUE->setPalette(Qt::lightGray);
        ui->lcdRED->display(QString::fromStdString("0"));
        ui->lcdGREEN->display(QString::fromStdString("0"));
        ui->lcdBLUE->display(QString::fromStdString("0"));

        ui->label->setText("Generated RGB map.");
        return;
    }
    ui->pic_label->setText("First please choose image to process!");

}
#包括 #包括 #包括 #包括 #包括 使用名称空间std; 作废生成(Ui::MainWindow*Ui) { 如果(用户界面->图片标签->像素贴图()!=0) { int cap=1024*4; int ct=32;//颜色公差 //整数颜色数第三个=256/颜色公差;//=256/32=8 int*uncompressedcolortable=新int[256*256*256]; 对于(int k=0;kpixmap()->width(); int height=ui->pic_label->pixmap()->height(); //整块瓷砖=宽度*高度; 如果((宽度>上限| |高度>上限)和&!(ui->ActionSuperson_sanity_check->isChecked()){ ui->label->setText(“文件太大,无法生成地图。如果仍要处理它,请选中菜单选项。”); 返回; } QImage image=ui->pic_label->pixmap()->toImage(); ui->lcdRED->setPalette(Qt::红色); ui->lcdGREEN->setPalette(Qt::绿色); ui->lcdBLUE->setPalette(Qt::blue); 用户界面->进度条->设置最大值(高度); QColor像素颜色; 流输出文件(“C:/Users/Niewzruszony/Desktop/map.map”); 输出文件进度条->设定值(j+1); } ui->lcdRED->setPalette(Qt::浅灰色); ui->lcdGREEN->setPalette(Qt::浅灰色); ui->lcdBLUE->setPalette(Qt::浅灰色); ui->lcdRED->display(QString::fromStdString(“0”); ui->lcdGREEN->display(QString::fromStdString(“0”); ui->lcdBLUE->显示(QString::fromStdString(“0”); ui->label->setText(“生成的RGB贴图”); 返回; } ui->pic_label->setText(“首先请选择要处理的图像!”); }
用Qt完成。我想我会分享代码的。
请注意,我在发帖时做了一些快速清理,以避免包含不重要的内容(至少不是全部)。

您可以使用类似的内容吗?很好,但我正在寻找类似的内容[链接]