CovertBmp.pas
上传用户:dgeyuang
上传日期:2007-01-11
资源大小:65k
文件大小:3k
- unit CovertBmp;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- Menus, ActnList,jpeg,math,extctrls;
- type
- TBMInfo = record
- bmType, //Bitmap类型
- bmWidth, //图像宽度(像素值)
- bmHeight, //图像高度(像素值)
- bmWidthBytes: longint; //每条扫描线指定的字节数
- bmPlanes, //指定颜色位
- bmBitsPixel: word; //色彩值
- //bmBits; //指向位图值地址
- end;
- Function CheckBmp(image: TImage;SourceName:string):Integer;
- function ConvertToBmp(image1:Timage;DestionName:String):string;
- implementation
- Function CheckBmp(image: TImage;SourceName:string):Integer;
- var
- bmInfo:TBMInfo;
- bmp:TBitmap;
- Ext:String;
- begin
- if not FileExists(SourceName) then
- begin
- result:=-1;
- exit;
- end;
- Ext:=LowerCase(ExtractFileExt(SourceName));
- if Ext='.bmp' then
- begin
- Screen.Cursor := crHourGlass;
- try
- image.Picture.LoadFromFile(SourceName);
- Image.top:=0;
- Image.left:=0;
- if Image.Picture.Graphic is TJPEGImage then
- begin
- bmp:=TBitmap.Create;
- bmp.Assign(TJPEGImage(Image.Picture.Graphic));
- end
- else bmp:=Image.Picture.Bitmap;
- GetObject(bmp.Handle,SizeOf(bmInfo),@bmInfo);
- case bmInfo.bmBitsPixel of
- 24: result:=24;
- 16: result:=16;
- else result:=Trunc(IntPower(2,bmInfo.bmBitsPixel));
- end;
- if(Image.Picture.Graphic is TJPEGImage) then bmp.free;
- finally
- Screen.Cursor := crDefault;
- end;
- end else Result:=-1;
- end;
- function ConvertToBmp(image1:Timage;DestionName:String):string;
- var
- bmp:TBitmap;
- i:integer;
- Picture:TPicture;
- begin
- // Picture:= TPicture.Create;
- try
- bmp := TBitmap.Create;
- image1.Picture.LoadFromFile(DestionName);
- Picture:=image1.Picture;
- if ( Picture.Graphic is TBitmap) then
- begin
- with Bmp do
- begin
- Width := Picture.Width;
- Height := Picture.Height;
- PixelFormat := pf8Bit;
- Canvas.Draw(0, 0, Picture.Graphic);
- end;
- Picture.Bitmap.Assign(Bmp);
- i:=Pos('.',DestionName);
- bmp.SaveToFile(Copy(DestionName,1,i-1)+'.Bmp');
- end else if Picture.Graphic is TJPEGImage then
- begin
- bmp:=TBitmap.create;
- bmp.Assign(TJPEGImage(Picture.Graphic));
- bmp.PixelFormat:=pf8bit;
- i:=Pos('.',DestionName);
- bmp.SaveToFile(Copy(DestionName,1,i-1)+'.Bmp');
- result:=Copy(DestionName,1,i-1)+'.Bmp';
- bmp.free;
- result:=Copy(DestionName,1,i-1)+'.Bmp';
- end;
- except
- end;
- end;
- end.