//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "BMPToJpg.h"
// *******
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
struct Color {
int R;
int G;
int B;
};
bool TForm1::bmpRead(vector<vector<cColor> > &imageVec, const char* fileName) {
ifstream file("lenna512.bmp",ios::in | ios::binary);
if (!file)
return false;
// skip header
const ifstream::off_type headerSize = 54;
file.seekg(headerSize, ios::beg);
// read body
for(size_t y = 0; y != imageVec.size(); ++y) {
for(size_t x = 0; x != imageVec[0].size(); ++x) {
char chR,chG,chB;
file.get(chB).get(chG).get(chR);
imageVec[y][x].B = chB;
imageVec[y][x].G = chG;
imageVec[y][x].R = chR;
}
}
file.close();
return true;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
const size_t sizey = 512;
const size_t sizex = 512;
vector<vector<cColor> > imageVec(sizey, vector<cColor>(sizex));
if (!bmpRead(imageVec, "lenna512.bmp")) {
//out << "Read image error!!" << endl;
ShowMessage("You are fire");
//return -1;
}
TImage *imgTarget;
imgTarget=new TImage(Application);
imgTarget->Parent = Panel1;
imgTarget->Height = sizey;
imgTarget->Width = sizex;
for(size_t y = 0; y != imageVec.size(); ++y) {
for(size_t x = 0; x != imageVec[0].size(); ++x) {
int B = (int)imageVec[y][x].B;
int G = (int)imageVec[y][x].G;
int R = (int)imageVec[y][x].R;
imgTarget->Canvas->Pixels[x][sizey -1 -y]=RGB(R,G,B);
//imgTarget->Canvas->Pen->Style=psClear;
//imgTarget->Canvas->Brush->Color = (TColor)RGB(90,90,90);
//imgTarget->Canvas->Rectangle(0,0,90,90);
}
}
}
//---------------------------------------------------------------------------
BMPToJpg.rar_BMPTOJPG
版权申诉
190 浏览量
2022-09-19
18:50:29
上传
评论
收藏 288KB RAR 举报
林当时
- 粉丝: 100
- 资源: 1万+