我有一个512*512的二进制点阵图文件!不知道该怎么读数据啊?读取数据后怎么样把图片显示出来?
解决方案 »
- 有没有更好的方法分解这个字符串,在线等
- 大家看看这个SQL语句怎么写?
- 遇到了好心人,请wizardqi进来接分
- DBGRID 输出3列,我坐一个打印按钮,一按就直接找到默认的打印机打印~高分,在线等
- 请问这里怎么样得分啊?
- DataModule中的ADOCONNENCTION数据源怎样初始化,放在哪儿?
- IntraWeb v5.0.35在D6下编译通不过,Why?
- 请问delphi的软件怎样发布??可否赐教??555。。。
- 关于Delphi5.0Enterprise Edition Update Pack 1的Serial number和 Authorize Code?
- 哪位大侠知道电子图书网址,计算机方面的,软件工程,delphi编程开发之类的
- listbox上记录上下移动
- delphi资料~~超多~生平尽见!
或者,你也可以用更快的方式Scanline
var
hbmp:HFILE;
bmfheader:bitmapfileheader;
nfilelen:longword;
bmpinfo:bitmapinfo;
bmpcol:array[0..255] of TRGBQuad;
ncolors:DWORD;
bitcount:WORD;
pal:PLogPalette;
move_sum:longWord;
ppal,Oldppal: hPalette;
//rect1:TRect;
hdib:HGLOBAL;
hdib1:HGLOBAL;
Compression:DWORD;
i,j,data_size:longWord;
k:array [0..1] of byte;
begin
result:=false;
hbmp:=_lopen(sbmpfile,OF_READ);//以二进制模式打开指定的文件
if hbmp=INVALID_HANDLE_VALUE then begin result:=false;exit;end;
nfilelen:=GetFileSize(hbmp,nil); //得到文件长度 //读文件头
if (_lread(hbmp,@bmfheader, sizeof(bitmapfileheader))<>sizeof(bitmapfileheader))then begin _lclose(hbmp);exit;end;
if bmfheader.bfType<>( (ord('M')shl 8) or (ord('B')) )then begin _lclose(hbmp);exit;end;
hdib:=GlobalAlloc(GMEM_FIXED,nfilelen-sizeof(bitmapfileheader)); //分配全局内存块 if (_lread(hbmp,pointer(hdib),nfilelen-sizeof(bitmapfileheader)))<>nfilelen-sizeof(bitmapfileheader)then //将文件读入内存块
begin
GlobalFree(hdib); //释放全局内存块
_lclose(hbmp);
exit;
end; copymemory(@bmpinfo,pointer(hdib),sizeof(bitmapinfo)); //从内存块中读位图信息
bitcount:=bmpinfo.bmiheader.biBitCount;
Compression:=bmpinfo.bmiheader.biCompression; move_sum:=0;
if bitcount<=8 then //读入颜色表数据
begin
if bmpinfo.bmiheader.biClrUsed>0 then
ncolors:=bmpinfo.bmiheader.biClrUsed
else
ncolors:=1 shl bitcount;
copymemory(@bmpcol,pointer(hdib+sizeof(TBitmapInfoHeader)),sizeof(TRGBQuad)*ncolors); //从内存块中读位图信息中的颜色表数据
GetMem(pal,sizeof(TLogPalette) + sizeof(TPaletteEntry) * (ncolors-1));
pal.palVersion:=$300;
pal.palNumEntries:=ncolors;
for i:=0 to ncolors-1 do
begin
pal.palPalEntry[i].peRed:=bmpcol[i].rgbRed;
pal.palPalEntry[i].peGreen:=bmpcol[i].rgbGreen;
pal.palPalEntry[i].peBlue:=bmpcol[i].rgbBlue;
pal.palPalEntry[i].peFlags:=bmpcol[i].rgbReserved; bmpinfo.bmiColors[i].rgbRed:=bmpcol[i].rgbRed;
bmpinfo.bmiColors[i].rgbGreen:=bmpcol[i].rgbGreen;
bmpinfo.bmiColors[i].rgbBlue:=bmpcol[i].rgbBlue;
bmpinfo.bmiColors[i].rgbReserved:=bmpcol[i].rgbReserved;
{
rect1.Left:=(i mod 16)*13;
rect1.Right:=rect1.Left+12;
rect1.Top:=(i div 16)*13;
rect1.Bottom:=rect1.Top+12;
image1.Canvas.Brush.Color:=rgb(pal.palPalEntry[i].peRed,pal.palPalEntry[i].peGreen,pal.palPalEntry[i].peBlue);
image1.Canvas.FillRect(rect1);
}
move_sum:=ncolors*sizeof(tagRGBQUAD);
end;
ppal:=createpalette(pal^); //建立逻辑调色板
FreeMem(pal); if (GetDeviceCaps(pdc,RASTERCAPS) and RC_PALETTE)>0 then
begin
oldppal:=selectpalette(pdc,ppal,false);//选择调色板
realizepalette(pdc); //逻辑调色板到硬件调色板的映射
end;
end; move_sum:=move_sum+sizeof(BitmapInfoHeader);
case Compression of //处理 压缩 位图信息数据
BI_RGB: //无压缩
begin
setdibitstodevice(pdc,0,0,bmpinfo.bmiHeader.biwidth,bmpinfo.bmiheader.biheight,
0,0,0,bmpinfo.bmiheader.biheight,pointer(hdib+move_sum),bmpinfo,DIB_RGB_COLORS);
end;
BI_RLE8: //BI_RLE8D压缩
begin
bmpinfo.bmiheader.biCompression:=0;
data_size:=((((bmpinfo.bmiHeader.biWidth*bmpinfo.bmiHeader.biBitCount+31)div 8)div 4)*4*bmpinfo.bmiHeader.biHeight);
hdib1:=GlobalAlloc(GMEM_FIXED,data_size+sizeof(BitmapInfo)); //分配全局内存块
zeromemory(pointer(hdib1),data_size+sizeof(BitmapInfo));
i:=0;j:=0;
while i<nfilelen-move_sum-sizeof(bitmapfileheader) do
begin //....解压位图数据
if (i>0)and((i mod 2)=1) then i:=i+1;
copymemory(@k,pointer(hdib+move_sum+i),2);
if k[0]<>0 then //连续数据解压
begin
FillMemory(pointer(hdib1+j),k[0],k[1]);
j:=j+k[0];
end
else //无连续数据解压
begin
i:=i+2;
copymemory(pointer(hdib1+j),pointer(hdib+move_sum+i),k[1]);
j:=j+k[1];
i:=i+k[1]-2;
end;
i:=i+2;
if j>data_size+sizeof(BitmapInfo)-1 then break;
end; setdibitstodevice(pdc,0,0,bmpinfo.bmiHeader.biwidth,bmpinfo.bmiheader.biheight,
0,0,0,bmpinfo.bmiheader.biheight,pointer(hdib1),bmpinfo,DIB_RGB_COLORS);
GlobalFree(hdib1);
end;
BI_RLE4:
begin
end;
BI_BITFIELDS:
begin end;
end; if oldppal<>0 then selectpalette(pdc,oldppal,false);
GlobalFree(hdib);
_lclose(hbmp);
result:=true;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
loadbmp('D:\4.bmp',image1.Canvas.Handle);
end;