将(文本文件)转换为任何格式的图像(png)C++

发布于 2024-11-05 17:44:47 字数 214 浏览 0 评论 0原文

有人可以给我提供一份 C++ 代码吗,用于将文本文件转换为任何格式的图像,我知道图像没有任何意义,但我这样做是出于安全原因,

有人可以给我提供一份 C++ 代码吗? ,如果没有C++,那么JAVA就可以工作

我在网上查了很多,并没有发现什么

我知道每个人都会说单独做你的工作,但我真的没有时间 拜托,这很严重 如果有人要

提前做的话我什至愿意付钱

can some one please provide me with a C++ code, for transforming a text file to any format of images, I know the image will have no meaning, but I am doing this thing for security reasons

can some one please provide me with a C++ code, if there is no C++ , then JAVA will work

I really checked alot on the net, and found really nothing

I know every one will say do ur job alone, but I am really out of time
please this is serious
I am even willing to pay if some one is goin to do it

thanx in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

因为看清所以看轻 2024-11-12 17:44:47

我不知道您想要什么转换,但您可以将文本文件中的文本视为无符号字符数组,并将此数据作为 RGB 数组存储到 BMP 或其他无损压缩图像格式中。对于加载和保存图像,有很多库(OpenIL/DevIL 非常简单且有用)。

这样,图像没有任何意义,但仍然是有效图像,与仅更改文件扩展名不同。

编辑:你的运气我现在很无聊。以下内容可以使用 OpenIL 进行工作:

#include <fstream>
#include <cmath>
#include <IL/il.h>

void encode(const char *infile, const char *outfile)
{
    std::ifstream in(infile);
    in.seekg(0, std::ios_base::end);
    unsigned int size = in.tellg();
    unsigned int width = (size+6) / 3;
    width = int(sqrt(double(width))) + 1;
    char *data = new char[width*width*3];
    *(unsigned int*)data = size;
    in.seekg(0);
    in.read(data+sizeof(unsigned int), size);
    unsigned int image;
    ilGenImages(1, &image);
    ilBindImage(image);
    ilTexImage(width, width, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, data);
    ilSaveImage(outfile);
    ilDeleteImages(1, &image);
    delete[] data;
}

void decode(const char *infile, const char *outfile)
{
    unsigned int image;
    ilGenImages(1, &image);
    ilBindImage(image);
    ilLoadImage(infile);
    ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
    unsigned char *data = ilGetData();
    unsigned int size = *(unsigned int*)data;
    std::ofstream out(outfile);
    out.write((char*)data+sizeof(unsigned int), size);
    ilDeleteImages(1, &image);
}

int main(int argc, char *argv[])
{
    ilInit();
    ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
    ilEnable(IL_ORIGIN_SET);
    ilEnable(IL_FILE_OVERWRITE);
    encode(argv[1], argv[2]);
    decode(argv[2], argv[3]);
    return 0;
}

编辑:添加了测试程序的完整源代码。在我的 Windows 系统上使用此代码作为输入和 PNG 格式对其进行了测试,它可以工作。

I do not know, what you want the transformation to be, but you can just treat the text from the text file as an array of unsigned chars and store this data as an RGB array into a BMP or another lossless compressed image format. For loading and saving images there are a plenty of libraries (OpenIL/DevIL is quite simple and useful).

This way the image has no meaning but is still a valid image, in contrast to just changing the file extension.

EDIT: Your luck I'm currently bored. The following could work using OpenIL:

#include <fstream>
#include <cmath>
#include <IL/il.h>

void encode(const char *infile, const char *outfile)
{
    std::ifstream in(infile);
    in.seekg(0, std::ios_base::end);
    unsigned int size = in.tellg();
    unsigned int width = (size+6) / 3;
    width = int(sqrt(double(width))) + 1;
    char *data = new char[width*width*3];
    *(unsigned int*)data = size;
    in.seekg(0);
    in.read(data+sizeof(unsigned int), size);
    unsigned int image;
    ilGenImages(1, &image);
    ilBindImage(image);
    ilTexImage(width, width, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, data);
    ilSaveImage(outfile);
    ilDeleteImages(1, &image);
    delete[] data;
}

void decode(const char *infile, const char *outfile)
{
    unsigned int image;
    ilGenImages(1, &image);
    ilBindImage(image);
    ilLoadImage(infile);
    ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
    unsigned char *data = ilGetData();
    unsigned int size = *(unsigned int*)data;
    std::ofstream out(outfile);
    out.write((char*)data+sizeof(unsigned int), size);
    ilDeleteImages(1, &image);
}

int main(int argc, char *argv[])
{
    ilInit();
    ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
    ilEnable(IL_ORIGIN_SET);
    ilEnable(IL_FILE_OVERWRITE);
    encode(argv[1], argv[2]);
    decode(argv[2], argv[3]);
    return 0;
}

EDIT: Added complete sourcecode of test program. Tested it on my Windows system with this code as input and the PNG format and it works.

故乡的云 2024-11-12 17:44:47

只需将文件扩展名更改为 .png 或任何您想要的。操作系统不知道文件中的内容及其含义;仅打开时使用什么程序。

如果您需要安全性,我建议您阅读一些有关加密的内容。

Just change the file extension to .png or whatever you want. Operating systems have no notion of what's in a file and what it means; only what program to use when opening it.

If you need security, I recommend reading up a bit on encryption.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文