谁能帮我看看这段代码呀 ( 积分: 50 )

  • 主题发起人 主题发起人 sunzhanwei
  • 开始时间 开始时间
S

sunzhanwei

Unregistered / Unconfirmed
GUEST, unregistred user!
代码:
<br>s:=isjpg(suilistbox1.Items.Strings[t]);<br>case s of<br>true:<br> &nbsp; Begin &nbsp;//是JPG图像格式,先转换为BMP文件格式,在设为墙纸<br> &nbsp; &nbsp; jpg2bmp(suilistbox1.Items.Strings[t],GetWinTempDir+'/TWPaper.DAP');<br> &nbsp; &nbsp; systemparametersinfo(SPI_SETDESKWALLPAPER,0,PChar(GetWinTempDir+'/TWPaper.DAP'),SPIF_UPDATEINIFILE or SPIF_SENDWININICHANGE);<br> &nbsp; &nbsp; k:=0;<br> &nbsp; &nbsp; t:=t+1;<br> &nbsp; End;<br>false:<br> &nbsp; Begin//是BMP文件,直接设置为墙纸<br> &nbsp; systemparametersinfo(SPI_SETDESKWALLPAPER,0,PChar(suilistbox1.Items.Strings[0]),SPIF_UPDATEINIFILE or SPIF_SENDWININICHANGE);<br> &nbsp; k:=0;<br> &nbsp; t:=t+1;<br> &nbsp; End;<br>//----------------------------------------------------------<br>function TForm1.IsJpg(const filename: string): boolean;<br>Var<br>b : Array[0..1] Of Byte;<br>fs : TFileStream;<br>s:string;<br>begin<br>//result:=false;<br> &nbsp;fs := TFileStream.Create(filename, fmOpenRead);<br> &nbsp;Try<br> &nbsp; &nbsp;fs.Read(b, 3);<br> &nbsp; &nbsp;s := IntToHex(b[0], 2) + IntToHex(b[1], 2);<br> &nbsp;Finally<br> &nbsp; &nbsp;FreeAndNil(fs);<br> &nbsp;End;<br>if s='FFD8' then<br>result:=true<br>else<br>result:=false;<br>end;<br>procedure TForm1.Jpg2Bmp(const source, dest: string);<br>var<br> &nbsp;MyJpeg: TJpegImage;<br> &nbsp;bmp: Tbitmap;<br>begin<br>bmp:=tbitmap.Create;<br>MyJpeg:= TJpegImage.Create;<br>try<br> &nbsp;myjpeg.LoadFromFile(source);<br> &nbsp;bmp.Assign(myjpeg);<br> &nbsp;bmp.SaveToFile(dest);<br>finally<br> &nbsp;bmp.free;<br> &nbsp;myjpeg.Free;<br>end;<br>end;<br>function TForm1.GetWinTempDir: String;<br>var<br> &nbsp;Path:array[0..Max_Path] of Char;<br>begin<br> &nbsp;Result:='';<br> &nbsp;try<br> &nbsp; &nbsp;GetTempPath(SizeOf(Path),Path);<br> &nbsp; &nbsp;Result:=StrPas(Path);<br> &nbsp;except<br> &nbsp;end;<br>end;<br>
<br>它总是在systemparametersinfo这个函数上出问题,到底是什么原因呀
 
代码:
<br>s:=isjpg(suilistbox1.Items.Strings[t]);<br>case s of<br>true:<br> &nbsp; Begin &nbsp;//是JPG图像格式,先转换为BMP文件格式,在设为墙纸<br> &nbsp; &nbsp; jpg2bmp(suilistbox1.Items.Strings[t],GetWinTempDir+'/TWPaper.DAP');<br> &nbsp; &nbsp; systemparametersinfo(SPI_SETDESKWALLPAPER,0,PChar(GetWinTempDir+'/TWPaper.DAP'),SPIF_UPDATEINIFILE or SPIF_SENDWININICHANGE);<br> &nbsp; &nbsp; k:=0;<br> &nbsp; &nbsp; t:=t+1;<br> &nbsp; End;<br>false:<br> &nbsp; Begin//是BMP文件,直接设置为墙纸<br> &nbsp; systemparametersinfo(SPI_SETDESKWALLPAPER,0,PChar(suilistbox1.Items.Strings[0]),SPIF_UPDATEINIFILE or SPIF_SENDWININICHANGE);<br> &nbsp; k:=0;<br> &nbsp; t:=t+1;<br> &nbsp; End;<br>//----------------------------------------------------------<br>function TForm1.IsJpg(const filename: string): boolean;<br>Var<br>b : Array[0..1] Of Byte;<br>fs : TFileStream;<br>s:string;<br>begin<br>//result:=false;<br> &nbsp;fs := TFileStream.Create(filename, fmOpenRead);<br> &nbsp;Try<br> &nbsp; &nbsp;fs.Read(b, 3);<br> &nbsp; &nbsp;s := IntToHex(b[0], 2) + IntToHex(b[1], 2);<br> &nbsp;Finally<br> &nbsp; &nbsp;FreeAndNil(fs);<br> &nbsp;End;<br>if s='FFD8' then<br>result:=true<br>else<br>result:=false;<br>end;<br>procedure TForm1.Jpg2Bmp(const source, dest: string);<br>var<br> &nbsp;MyJpeg: TJpegImage;<br> &nbsp;bmp: Tbitmap;<br>begin<br>bmp:=tbitmap.Create;<br>MyJpeg:= TJpegImage.Create;<br>try<br> &nbsp;myjpeg.LoadFromFile(source);<br> &nbsp;bmp.Assign(myjpeg);<br> &nbsp;bmp.SaveToFile(dest);<br>finally<br> &nbsp;bmp.free;<br> &nbsp;myjpeg.Free;<br>end;<br>end;<br>function TForm1.GetWinTempDir: String;<br>var<br> &nbsp;Path:array[0..Max_Path] of Char;<br>begin<br> &nbsp;Result:='';<br> &nbsp;try<br> &nbsp; &nbsp;GetTempPath(SizeOf(Path),Path);<br> &nbsp; &nbsp;Result:=StrPas(Path);<br> &nbsp;except<br> &nbsp;end;<br>end;<br>
<br>它总是在systemparametersinfo这个函数上出问题,到底是什么原因呀
 
自己搞定了<br>
代码:
function TForm1.IsJpg(const filename: string): boolean;<br>Var<br>b : Array[0..1] Of Byte;[code]
<br>fs : TFileStream;<br>s:string;<br>begin<br>//result:=false;<br> &nbsp;fs := TFileStream.Create(filename, fmOpenRead);<br> &nbsp;Try<br> &nbsp; &nbsp;fs.Read(b, 3);<br> &nbsp; &nbsp;s := IntToHex(b[0], 2) + IntToHex(b[1], 2);<br> &nbsp;Finally<br> &nbsp; &nbsp;FreeAndNil(fs);<br> &nbsp;End;<br>if s='FFD8' then<br>result:=true<br>else<br>result:=false;<br>end;[/code]把这段代码改为<br>
代码:
function TForm1.IsJpg(const filename: string): boolean;<br>Var<br>b : Array[0..1] Of Byte;<br>fs : TFileStream;<br>s:string;<br>begin<br>//result:=false;<br> &nbsp;fs := TFileStream.Create(filename, fmOpenRead);<br> &nbsp;Try<br> &nbsp; &nbsp;fs.Read(b, 3);<br> &nbsp; &nbsp;s := IntToHex(b[0], 2) + IntToHex(b[1], 2);<br> &nbsp; if s='FFD8' then<br>result:=true<br>else<br>result:=false;<br> &nbsp;Finally<br> &nbsp; &nbsp;FreeAndNil(fs);<br> &nbsp;End;<br><br>end;
 
后退
顶部