2022企业服务(新型)提供商TOP150
全世界各行各业联合起来,internet一定要实现!

将JPEG文件转为Windows墙纸

2004-02-14 eNet&Ciweek

  JPEG是一种图像压缩标准,很多精美的图片都是采用这种格式标准,其特点是文件体积较小,而且支持24位色深。但是,Windows9x只支持位图文件(即以bmp为扩展名的文件)的墙纸。下面这个程序就是将以jpg或jpeg为扩展名的图片文件转化为位图文件,并通过修改注册表的键值来通知Windows更换墙纸。本程序使用了一个Tform;一个OpenPictureDialog用来让用户选择图片;三个SpeedButton;分别用来打开OpenPictureDialog对话框,确定更换墙纸,退出程序。程序全部代码如下:

    unit Unit1;

    interface

    uses

     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,

  Dialogs, jpeg, registry, ExtDlgs, StdCtrls, Buttons;

    type

     TForm1 = class(Tform)

     SpeedButton1: TSpeedButton;

     SpeedButton2: TSpeedButton;

     SpeedButton3: TSpeedButton;

     OpenPictureDialog1: TOpenPictureDialog;

    procedure SpeedButton1Click(Sender: Tobject);

    procedure SpeedButton2Click(Sender: Tobject);

    procedure SpeedButton3Click(Sender: Tobject);

     private

     { Private declarations }

     public

     { Public declarations }

     end;

    var

     Form1: TForm1;

    implementation

    {$R *.DFM}

    procedure TForm1.SpeedButton1Click(Sender: Tobject);

    begin

     openpicturedialog1.execute;{打开OpenPictureDialog对话框}

    end;

    procedure TForm1.SpeedButton2Click(Sender: Tobject);

    var

     reg: tregistry;{Tregistry对象在Registry单元中声明,需要在Uese 中引用Registry单元}

     jpeg: tjpegimage;{Tjpegimage对象在Jpeg单元中声明,需要在Uese 中引用Jpeg单元}

     bmp: tbitmap;

    begin

     if (openpicturedialog1.filename=``)

     then {判断OpenPictureDialog1中有无文件被选中}

  messagedlg(`请选择一张图片`,mtinformation,[mbOK],0)

     else

     begin

     jpeg:=tjpegimage.Create;

     jpeg.LoadFromFile(openpicturedialog1.filename);{加载被用户选中的文件}

     bmp:=tbitmap.Create;

     bmp.assign(jpeg);

     bmp.savetofile(`c:\windows\wall.bmp`);{将转换成功的文件保存的路径及文件名}

     reg:=tregistry.Create;

    reg.rootkey:=hkey_current_user;{设置根键名称}

    reg.openkey(`control panel\desktop`,false);{打开Control Panel\Desktop路径对应的主

  键}

     reg.writestring(`tilewallpaper`,`0`);

     reg.writestring(`wallpaper`,`c:\windows\wall.bmp`);

  {覆盖并写入新值TileWall- paper和Wallpaper串}

    systemparametersinfo(spi_setdeskwallpaper,0,nil,spif_sendchange);{通知win-dows更

  换墙纸}

    reg.closekey;{写入更改内容并关闭注册表}

     reg.Free;{释放对象}

     close;

     end;

    end;

    procedure TForm1.SpeedButton3Click(Sender: Tobject);

    begin

     close;

    end;

    end.

    此程序只能将以jpg或jpeg为扩展名的图片文件转化为Windows的墙纸,因此应在OpenPictureDialog控件的Filter属性中筛选显示文件的类型,最好设置为JPEG Image File(*.jpg)和JPEG Image File(*.jpeg)文件。

相关频道: eNews

您对本文或本站有任何意见,请在下方提交,谢谢!

投稿信箱:tougao@enet16.com