⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 picto161.cpp

📁 彩色图片转16进制格式软件源码
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <stdio.h>
//#include <wingdi.h>
#include <vcl.h>
#pragma hdrstop

#include "PicTo161.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

String          picture_address;

void __fastcall TForm1::Button1Click(TObject *Sender)
{


        //static const unsigned char DEMO256[]={

        FILE    *ftxt;
        int     bmp_width,bmp_heigth;
        long    colour_value;
        int     red_value,green_value,blue_value;
        String  count_print;
        String  txt_head_show;

        if(Edit1->Text=="")
        {
                ShowMessage("没有输入保存文件!");
                return;
        }

        ftxt=fopen(Edit1->Text.c_str() ,"w");
        if(ftxt==NULL)
        {
                fcloseall;
                ShowMessage("保存文件错误!");
                return;
        }

        bmp_width=Image1->Width;

        bmp_heigth=Image1->Height;

        if(bmp_width==0||bmp_heigth==0)
        {
                ShowMessage("没有输入图片!");
                return;
        }

        txt_head_show="/* \n Bitmap点阵数据表图片:"+picture_address+"\n";
        fprintf(ftxt,"%s",txt_head_show);
        txt_head_show=" 图片数据排列:R,G,B";
        fprintf(ftxt,"%s\n",txt_head_show);
        txt_head_show=" 图片尺寸: "+IntToStr(bmp_width)+"×"+IntToStr(bmp_heigth)+"\n"+"*/"+"\n";
        fprintf(ftxt,"%s\n",txt_head_show);

        txt_head_show="static const unsigned char "+ChangeFileExt(ExtractFileName(picture_address),"")+"[]={";
        fprintf(ftxt,"%s\n",txt_head_show);



        for(int k=0;k<bmp_heigth;k++)
        {
                for(int l=0;l<bmp_width;l++)
                {
                        colour_value=Image1->Canvas->Pixels[l][k];
                        red_value=GetRValue(colour_value);
                        green_value=GetGValue(colour_value);
                        blue_value=GetBValue(colour_value);
                        count_print="0x"+IntToHex(red_value,2)+"  "+"0x"+IntToHex(green_value,2)+"  "+"0x"+IntToHex(blue_value,2)+"  ";
                        fprintf(ftxt,"%s",count_print);
                }
        }
        fprintf(ftxt,"%s\n","");
        fprintf(ftxt,"%s\n","}");
        ShowMessage("转换完毕!");
        fclose(ftxt);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
        OpenDialog1->Execute();
        if(OpenDialog1->FileName!="")
        {
                int     temp1,temp2;
                Image1->Picture->LoadFromFile(OpenDialog1->FileName);
                picture_address=OpenDialog1->FileName;
                temp1=Panel1->Width;
                temp2=Image1->Width;
                Image1->Top=(temp1-temp2)/2;
                temp1=Panel1->Height;
                temp2=Image1->Width ;
                Image1->Left=(temp1-temp2)/2;
        }

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
        SaveDialog1->Execute();
        if(SaveDialog1->FileName!="")
        {
                Edit1->Text=SaveDialog1->FileName;
        }
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -