首页 > 其他分享 >读取文本十六进制,保存为图片

读取文本十六进制,保存为图片

时间:2024-09-26 18:45:02浏览次数:5  
标签:十六进制 读取 hex file output 文本 png

读取文本十六进制,保存为图片

目录结构

D:\SFW\PY_TOOLS\PNGPY
    main.py
    mhex.txt
    output.png

main.py

def hex_to_png(hex_file, output_file):
    # 从文件中读取十六进制数据
    with open(hex_file, 'r') as f:
        hex_data = f.read().strip()  # 读取并去除多余的空格和换行

    # 将十六进制字符串转换为字节
    byte_data = bytes.fromhex(hex_data)

    # 将字节数据写入 PNG 文件
    with open(output_file, 'wb') as f:
        f.write(byte_data)

if __name__ == "__main__":
    hex_file = 'mhex.txt'  # 输入的十六进制文件名
    output_file = 'output.png'  # 输出的 PNG 文件名

    hex_to_png(hex_file, output_file)
    print(f"PNG 文件已写入: {output_file}")

mhex.txt

89504E470D0A1A0A0000000D4948445200000500000002D00802000000401F4A01000000017352474200AECE1CE90000000467414D410000B18F0BFC61050000000970485973000012740000127401DE661F7800000A8F49444154785EEDC13101000000C2A0F54FED6F0620000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E0D400354600018F1F0F6C0000000049454E44AE426082

output.png

就是一张图片,这里就不贴出来了

标签:十六进制,读取,hex,file,output,文本,png
From: https://www.cnblogs.com/jarico/p/18434067

相关文章

  • VB.net(C#同理)使用 ServiceStack.Redis 二进制存储、读取图像
    搜索了一下,网上似乎没有相关的内容,于是把自己探索的经验写一下。'安装提示:首先需要把当前的目标框架设置为.NetFramwork4.5。'方法一:复制ebay订单里的DLL\ServiceStack.Redis(整个文件夹),自行添加引用(4个dll)'方法二:使用Nuget安装servicestack.redis,选择5.0版本PublicClas......
  • 工具类,关于手工读取 properties文件参数
     importjava.io.*;importjava.util.Enumeration;importjava.util.Properties;importjava.util.Vector;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importorg.springframework.core.io.ClassPathResource;importorg.springframework.util.ResourceUtils;......
  • 欺诈文本分类检测(十六):支持分类原因评测改造
    1.引言经过前文对数据的校正与增强后,我们的预期生成结果中不再仅仅是分类标签,还多了欺诈者和分类原因。这样之前模型评测和批量评测两篇文章所封装的evaluate.py脚本就不再满足,需要对脚本进行改造,以支持新输出内容的评测。新的预期结果中共包含三个信息,由于三个信息的特......
  • RC522 NFC Reader,解决无法读取完整内存数据【Arduino IDE】
    目录一、前言二、项目概要三、实验测试(一)读取uid(二)读取内存与写入内存回到开头提到的两个问题:第一种情况读不全数据,//TrythempagesoftheoriginalUltralight.UltralightChasmorepages.第二种情况:直接无法读出数据,有时候甚至是一开始读得出,后来突然又读不出了......
  • java读取寄存器数据
    一:概述在嵌入式系统或硬件编程中,Java通常不是首选语言,因为它运行在虚拟机上,与硬件层面的交互不够直接。然而,随着Java技术的发展,以及JNA(JavaNativeAccess)等库的出现,使得Java也能进行一些底层操作,包括读取寄存器数据。本文将探讨几种在Java中读取寄存器数据的方法,并提供实际案例。......
  • java读取寄存器数据
    一:概述在嵌入式系统或硬件编程中,Java通常不是首选语言,因为它运行在虚拟机上,与硬件层面的交互不够直接。然而,随着Java技术的发展,以及JNA(JavaNativeAccess)等库的出现,使得Java也能进行一些底层操作,包括读取寄存器数据。本文将探讨几种在Java中读取寄存器数据的方法,并提供实际案例。......
  • RusTitW:大规模语言视觉文本识别数据集(猫脸码客 第190期)
    RusTitW:RussianLanguageVisualTextRecognition一、引言在信息爆炸的现代社会,文本作为信息传递的重要载体,扮演着不可或缺的角色。随着计算机视觉与模式识别技术的飞速发展,自动化文本识别(OCR,OpticalCharacterRecognition)技术日益成熟,极大地提升了信息处理的效率与准确性。......
  • 文件读取与查看
    一、读取publicStringsetFileName(){StringBuilderstrFile=newStringBuilder();StringfilePath="你的路径";Filedirectory=newFile(filePath);//确保路径确实指向一个目录if(directory.exists()&&directory.isDirectory()){......
  • 【C#】文件读取 -- .xml文件读取
    .xml文件读取与写入[实现效果][实现编程]///<summary>///创建xml配置///</summary>///<paramname="path">path,如:x:\\xxxx\\xxx.xml</param>privatevoidcreateXmlText(stringpath){if(string.IsNullOrEmpty(path))return......
  • 文本摘要综述—从统计方法到大型语言模型综述介绍,原文阅读:A Systematic Survey of Tex
    ASystematicSurveyofTextSummarization:FromStatisticalMethodstoLargeLanguageModels文本摘要的系统综述:从统计方法到大型语言模型paper:https://arxiv.org/abs/2406.11289文章目录~原文阅读Abstract1.Introduction1.1.MajorDifferences1.2.MainContri......