BMP图像数据提取不正确求救
我使用在Image控件里读点的方式来提取BMP图像的数据,然后转换成RGB565格式,分成低位和高位两个字节输出,但是得到的结果里面每隔256个正确数据就有64个变成了FF,但我用直接读内存的方式得到的就是正确数据。贴出问题程序,请高手们给参考。其中fp在头文件里定义为私有变量: ofstream fp
#include <vcl.h>
#pragma hdrstop
#include <fstream.h>
#include <assert.h>
#include "OBMP1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
char RC,GC,BC;
char RGH;
char GBL;
int x,y;
OpenPictureDialog1->Filter="BMP文件(*.BMP)|*.BMP";
if(OpenPictureDialog1->Execute())
{ //if1
fp.open("ttt.bin",ios::out|ios::hex);
assert(fp);
}else{
exit(1);
}
for(int a=0;a<OpenPictureDialog1->Files->Count;a++)
{
Image1->Picture->LoadFromFile(OpenPictureDialog1->Files->Strings[a]);
x=Image1->Picture->Width;
y=Image1->Picture->Height;
for(int i=0;i<x;i++)
for(int j=0;j<y;j++)
{ //for1
TColor color=Image1->Canvas->Pixels[j][i];//ÉùÃ÷²¢¶¨ÒåÑÕÉ«ÀàÎļþ
RC=GetRValue(color); //ÌáÈ¡Èý¶Ë×ÓÊý¾Ý
GC=GetGValue(color);
BC=GetBValue(color);
RGH=(RC&0xf8)|((GC&0xe0)/32);
GBL=((GC&0x1c)*8)|((BC&0xf8)/8);
fp<<GBL<<RGH
}
}
}
问题点数:100、回复次数:10Top
1 楼Aishion(纯属虚构)回复于 2004-09-03 17:48:39 得分 0
刚才乱码,重发程序
#include <vcl.h>
#pragma hdrstop
#include <fstream.h>
#include <assert.h>
#include "OBMP1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
char RC,GC,BC;
char RGH;
char GBL;
int x,y;
OpenPictureDialog1->Filter="BMP文件(*.BMP) ¦*.BMP";
if(OpenPictureDialog1->Execute())
{ //if1
fp.open("ttt.bin",ios::out ¦ios::hex);
assert(fp);
}else{
exit(1);
}
for(int a=0;a<OpenPictureDialog1->Files->Count;a++)
{
Image1->Picture->LoadFromFile(OpenPictureDialog1->Files->Strings[a]);
x=Image1->Picture->Width;
y=Image1->Picture->Height;
for(int i=0;i<x;i++)
for(int j=0;j<y;j++)
{ //for1
TColor color=Image1->Canvas->Pixels[j][i
RC=GetRValue(color);
GC=GetGValue(color);
BC=GetBValue(color);
RGH=(RC&0xf8) ¦((GC&0xe0)/32);
GBL=((GC&0x1c)*8) ¦((BC&0xf8)/8);
fp<<GBL<<RGH
}
}
}Top
2 楼Aishion(纯属虚构)回复于 2004-09-04 00:12:09 得分 0
大虾哪里去了?Top
3 楼Aishion(纯属虚构)回复于 2004-09-06 08:55:28 得分 0
有人来帮忙吗?Top
4 楼jiangchun_xn(GrayMemory)(再回头·灯火依旧·人不见·潸然泪下)回复于 2004-09-06 09:37:36 得分 60
TColor color=Image1->Canvas->Pixels[j][i];
改成:
TColor color=Image1->Canvas->Pixels[i][j];
看看
Top
5 楼Aishion(纯属虚构)回复于 2004-09-06 10:29:49 得分 0
谢谢!的确是这里的毛病,不过最终生成的数据有的正好没问题,有的图片生成的数据要比实际数据多几个数。Top
6 楼jiangchun_xn(GrayMemory)(再回头·灯火依旧·人不见·潸然泪下)回复于 2004-09-06 11:02:08 得分 0
这种方式还是比较慢的,用Scanline,或者GetDIBits API来操作内存可能会块很多Top
7 楼Aishion(纯属虚构)回复于 2004-09-06 11:24:01 得分 0
最简单就是直接从BMP文件中读取,那个是没问题的。Top
8 楼jiangchun_xn(GrayMemory)(再回头·灯火依旧·人不见·潸然泪下)回复于 2004-09-06 12:21:51 得分 0
那就给分吧
^_^Top
9 楼clong320(clong320)回复于 2004-09-06 15:05:33 得分 40
for (y = 0; y < Image1->Height; y ++)
{
for (x = 0; x < Image1->Width / 8; x ++)
{
PixelsArray[y][x] = 0x00;
for (i = 0; i < 8; i++)
{
tmpColor = BmpImage->Canvas->Pixels[x * 8 + i][y];
R = (int)GetRValue(tmpColor);
G = (int)GetGValue(tmpColor);
B = (int)GetBValue(tmpColor);
}
}
}
Top
10 楼Aishion(纯属虚构)回复于 2004-09-06 16:02:28 得分 0
好像不太好使~~老大们,接分啦Top




