将(文本文件)转换为任何格式的图像(png)C++
Converting a ( text file ) into any format of image ( png ) C++
有人可以给我一个C++代码,用于将文本文件转换为任何格式的图像,我知道图像没有任何意义,但是出于安全原因,我正在做这件事
有人可以给我一个C++代码,如果没有C++,那么JAVA就可以工作
了我真的在网上查了很多,真的什么也没找到
我知道每个人都会说一个人做你的工作,但我真的没时间了请这是严重的如果有人愿意这样做,我什至愿意付钱
提前致谢
我不知道
您希望转换是什么,但是您可以将文本文件中的文本视为无符号字符数组,并将此数据存储为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 格式对其进行了测试,它可以工作。
只需将文件扩展名更改为.png
或任何您想要的内容即可。 操作系统不知道文件中的内容及其含义;只有打开它时使用什么程序。
如果您需要安全性,我建议您阅读一些有关加密的信息。
相关文章:
- Qt-png图像未显示在部署应用程序中
- C++gdi::内存中的位图到PNG图像
- 当我调用它来解码 Blob 对象中的 png 图像时,"Magick++::readImages"引发警告
- 如何将 2d 数组转换为 svg 或 png 格式的数独图像?
- 为什么PNG图像的stdout有时会在printf中刷新图像的一半
- 为嵌入式系统加载 png 图像
- 如何在使用 c++/COM 发送时在电子邮件中插入/嵌入图像文件(.png)
- OPENCV IMREAD 8BPP PNG图像错误
- 如何使用我的C程序将PDF转换为图像格式(jpeg,png,..)
- OpenGL - SOIL 不会加载 JPG 或 PNG 图像
- 如何使用OPENCV C 将24位转换为8位深度PNG图像
- 如何使用GDI 显示具有25%不透明度的PNG图像?(MFC)
- 是否可以将 JPEG(或 PNG)类型的图像设置为 exe(C++)
- 使用 QPixmap 和 QLabel 在 Qt Creator 中以编程方式添加图像文件 (.PNG)
- 使用libCurl和GdkPixBuff将图像从JPEG保存为PNG
- 在 MFC 窗口中使用 PNG 作为背景图像
- 如何发送/接收例如图像(.png, .jpg)
- 如何在程序的内存中搜索图像/png/jpeg/任何其他类型并显示它
- 将(文本文件)转换为任何格式的图像(png)C++
- 图像 (PNG) 未显示在 c++ Win32 项目的最终执行中