码迷,mamicode.com
首页 > Windows程序 > 详细

Delphi常见图象格式转换技术

时间:2015-11-27 23:25:33      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

TJPEGScale = (jsFullSize, jsHalf, jsQuarter, jsEighth);//图片大小(全部,1/2,1/4,1/8)
TBitmap.pixelFormat:=pf8bit;//图片位数(8,24)

 

 

给大家提供几个常用的图象格式转换方法和其转换函数
希望可以对你有帮助
1. ICO图标转换BMP格式
2. 32x32 BMP格式图象转换为 ICO格式
3.转换BMP->JPEG文件格式
4.JPEG 转换为BMP函数
5.Bmp转换为JPEG文件格式函数
------------------------------------------------------------------------------------------
1.Chinese : ICO图标转换BMP格式
English :(Conversion from ICO to BMP)
--------------------------------------------------------

  var
    Icon   : TIcon;
    Bitmap : TBitmap;
  begin
     Icon   := TIcon.Create;
     Bitmap := TBitmap.Create;
     Icon.LoadFromFile(‘c:\picture.ico‘);
     Bitmap.Width := Icon.Width;
     Bitmap.Height := Icon.Height;
     Bitmap.Canvas.Draw(0, 0, Icon );
     Bitmap.SaveToFile(‘c:\picture.bmp‘);
     Icon.Free;
     Bitmap.Free;
===================================
2.Chinese: 32x32 BMP格式图象转换为 ICO格式
English :32x32 bit Bitmaps to ICO‘s
-----------------------------------

procedure TForm1.Button1Click(Sender: TObject);
var winDC, srcdc, destdc : HDC;
    oldBitmap : HBitmap;
    iinfo : TICONINFO;
begin
    GetIconInfo(Image1.Picture.Icon.Handle, iinfo);

    WinDC := getDC(handle);
    srcDC := CreateCompatibleDC(WinDC);
    destDC := CreateCompatibleDC(WinDC);
    oldBitmap := SelectObject(destDC, iinfo.hbmColor);
    oldBitmap := SelectObject(srcDC, iinfo.hbmMask);

    BitBlt(destdc, 0, 0, Image1.picture.icon.width,
     Image1.picture.icon.height,
           srcdc, 0, 0, SRCPAINT);
    Image2.picture.bitmap.handle := SelectObject(destDC, oldBitmap);
    DeleteDC(destDC);
    DeleteDC(srcDC);
    DeleteDC(WinDC);

image2.Picture.Bitmap.savetofile(ExtractFilePath(Application.ExeName)
          + ‘myfile.bmp‘);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  image1.picture.icon.loadfromfile(‘c:\myicon.ico‘);
end;

end.
==================================================================
3. Chinese:转换BMP->JPEG文件格式
Englsh:convert the bitmap into a JPEG file format
------------------------------------------------------------------
var
  MyJpeg: TJpegImage;
  Image1: TImage;
begin
  Image1:= TImage.Create;
  MyJpeg:= TJpegImage.Create;
  Image1.LoadFromFile(‘TestImage.BMP‘);  // 读取Bitmap文件
  MyJpeg.Assign(Image1.Picture.Bitmap);  
object
  MyJpeg.SaveToFile(‘MyJPEGImage.JPG‘); //保存JPEG
end;

--------------------------------------------------------------------
4.JPEG 转换为BMP函数

procedure Jpg2Bmp(const source,dest:string);
var
  MyJpeg: TJpegImage;
  bmp: Tbitmap;
begin
bmp:=tbitmap.Create;
MyJpeg:= TJpegImage.Create;
try
  myjpeg.LoadFromFile(source);
  bmp.Assign(myjpeg);
  bmp.SaveToFile(dest);
finally
  bmp.free;
  myjpeg.Free;
end;
end;

----------------------------------------------------------
5.Bmp转换为JPEG文件格式函数
----------------------------------------------------------
procedure Bmp2Jpg(const source,dest:string;const scale:byte);
var
  MyJpeg: TJpegImage;
  Image1: TImage;
begin
Image1:= TImage.Create(application);
MyJpeg:= TJpegImage.Create;
try
  Image1.Picture.Bitmap.LoadFromFile(source);
  MyJpeg.Assign(Image1.Picture.Bitmap); 
  MyJpeg.CompressionQuality:=scale;
  MyJpeg.Compress;
  MyJpeg.SaveToFile(dest);
finally
  image1.free;
  myjpeg.Free;
end;
end;
-----------------------------------------------------------------------

http://www.cnblogs.com/FKdelphi/p/4654575.html

Delphi常见图象格式转换技术

标签:

原文地址:http://www.cnblogs.com/findumars/p/5001801.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!