1、打开BMP图片文件,在Image控件中显示;
if(dlgOpen1->Execute()) { edt1->Text=dlgOpen1->FileName; img1->Picture->LoadFromFile(edt1->Text); }
2、逐行扫描图片,获取图片中每点的像素颜色值; color=img1->Canvas->Pixels[i][j];
3、从获取的颜色值中提取R、G、B分量; rgbbuf[0][i][j]=GetRValue(color); rgbbuf[1][i][j]=GetGValue(color); rgbbuf[2][i][j]=GetBValue(color);
BMP与JPG格式的相互转换
函数代码如下,在程序头文件中加入:#include <jpeg.hpp>
void bmptojpeg(TMemoryStream *pms) { TJPEGImage *j=new TJPEGImage; Graphics::TBitmap *b=new Graphics::TBitmap; b->LoadFromStream(pms); j->Assign(b); j->CompressionQuality=60; //等级太高有可能压缩出错! j->Compress(); pms->Clear(); j->SaveToStream(pms); pms->Position=0; delete b; delete j; } void jpegtobmp(TMemoryStream *pms) { TJPEGImage *j=new TJPEGImage; Graphics::TBitmap *b=new Graphics::TBitmap; j->LoadFromStream(pms); j->DIBNeeded(); b->Assign(j); pms->Clear(); b->SaveToStream(pms); pms->Position=0; delete b; delete j; }
要将转换后的流保存成文件可以使用:SaveToFile方法保存;