对于这个问题,楼主给的分数太少了。下面给你一个读取并显示PSD文件的代码(只处理压缩方法为RLE,且象素格式为RGB的PSD文件,代码参考http://www.codeproject.com/bitmap/MyPSD.asp)type TPSDFileHeader=record Signature:array[0..3] of char; Version:Word; Reserved:array[0..5] of Byte; Channels:Word; Height:Integer; Width:Integer; BitsPerPixel:Word; ColorMode:Word;end;function Calc(c:array of Byte;nDigits:integer):integer;var n,nValue:integer;begin nValue:=0; for n:=0 to nDigits-1 do nValue:=nValue shl 8 or c[n]; result:=nValue;end;procedure TForm1.Button1Click(Sender: TObject);var fs:TFileStream; PSDFH:TPSDFileHeader; TmpBuf:array[0..5] of Byte; i,iLen,iValue,Count,iTotalBytes,iPixels:Integer; pData,p,pDest
Byte; hMemDC:HDC; BmpInfo:BITMAPINFO; pp
ointer; hBmp:HBitmap;begin fs:=TFileStream.Create('1.psd',fmOpenRead); try //Read File Header fs.ReadBuffer(PSDFH.Signature,sizeof(PSDFH.Signature)); fs.ReadBuffer(TmpBuf,2); PSDFH.Version:=Calc(TmpBuf,2); fs.ReadBuffer(PSDFH.Reserved,sizeof(PSDFH.Reserved)); fs.ReadBuffer(TmpBuf,2); PSDFH.Channels:=Calc(TmpBuf,2); fs.ReadBuffer(TmpBuf,4); PSDFH.Height:=Calc(TmpBuf,4); fs.ReadBuffer(TmpBuf,4); PSDFH.Width:=Calc(TmpBuf,4); fs.ReadBuffer(TmpBuf,2); PSDFH.BitsPerPixel:=Calc(TmpBuf,2); fs.ReadBuffer(TmpBuf,2); PSDFH.ColorMode:=Calc(TmpBuf,2); //Read Color fs.ReadBuffer(TmpBuf,4); iLen:=Calc(TmpBuf,4); fs.Seek(iLen,soFromCurrent); //Read Image Source fs.ReadBuffer(TmpBuf,4); iLen:=Calc(TmpBuf,4); fs.Seek(iLen,soFromCurrent); //Read Layer fs.ReadBuffer(TmpBuf,4); iLen:=Calc(TmpBuf,4); fs.Seek(iLen,soFromCurrent); //压缩方法 fs.ReadBuffer(TmpBuf,2); iLen:=Calc(TmpBuf,2); if (iLen=1) and (PSDFH.ColorMode=3) then begin iPixels:=PSDFH.Width*PSDFH.Height; iTotalBytes:=iPixels*PSDFH.BitsPerPixel div 8*PSDFH.Channels; GetMem(pData,iTotalBytes); p:=pData; fs.Seek(PSDFH.Height*PSDFH.Channels*2,soFromCurrent); for i:=0 to PSDFH.Channels-1 do begin Count:=0; while Count<iPixels do begin fs.ReadBuffer(TmpBuf,1); iLen:=Calc(TmpBuf,1); if 128>iLen then begin inc(iLen); inc(Count,iLen); while iLen<>0 do begin fs.ReadBuffer(TmpBuf,1); iValue:=Calc(TmpBuf,1); p^:=iValue; inc(p); dec(iLen); end; end else if 128<iLen then begin iLen:=iLen xor $FF; inc(iLen,2); fs.ReadBuffer(TmpBuf,1); iValue:=Calc(TmpBuf,1); inc(Count,iLen); while iLen<>0 do begin p^:=iValue; inc(p); dec(iLen); end; end; end; end; p:=pData; GetMem(pDest,iTotalBytes); for i:=0 to PSDFH.Channels-1 do begin Count:=i; for iLen:=0 to iPixels-1 do begin PByte(Integer(pDest)+Count)^:=p^; inc(p); inc(Count,3); end; end; BmpInfo.bmiHeader.biSize:=sizeof(BITMAPINFOHEADER); BmpInfo.bmiHeader.biWidth:=PSDFH.Width; BmpInfo.bmiHeader.biHeight:=-PSDFH.Height; BmpInfo.bmiHeader.biPlanes:=1; BmpInfo.bmiHeader.biBitCount:=24; BmpInfo.bmiHeader.biCompression:=BI_RGB; BmpInfo.bmiHeader.biSizeImage:=0; BmpInfo.bmiHeader.biXPelsPerMeter:=0; BmpInfo.bmiHeader.biYPelsPerMeter:=0; BmpInfo.bmiHeader.biClrImportant:=0; BmpInfo.bmiHeader.biClrUsed:=0; hBmp:=CreateDIBSection(GetDC(0),BmpInfo, DIB_RGB_COLORS,pp,0,0); hMemDC:=CreateCompatibleDC(0); SelectObject(hMemDC,hBmp); Count:=0; while Count<iTotalBytes do //Swap b to r begin iLen:=PByte(Integer(pDest)+Count+2)^; PByte(Integer(pDest)+Count+2)^:=PByte(Integer(pDest)+Count)^; PByte(Integer(pDest)+Count)^:=iLen; inc(Count,3); end; Move(pDest^,pp^,iTotalBytes); BitBlt(Canvas.Handle,0,0,PSDFH.Width,PSDFH.Height, hMemDC,0,0,SRCCOPY); DeleteDC(hMemDC); FreeMem(pDest); FreeMem(pData); end; finally fs.Free; end;end;