在delphi中怎么样把JPEG,bmp,png,tif等格式文件转换为JPG RT,要求转换后图像的大小可以设定,图像的质量也可以调节,怎么样实现,我研究了好几天了,但没有搞定,请各位大侠帮忙!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 研究几天就想搞定?好几天时间各种格式的文档都找齐了不?好像就算只是写代码几天都不够啊,我也是研究了几年才搞定你说的这些.除非你找来现成的库,比如Delphi可以用GraphicEx,C++可以用CxImage,重取样和格式转换都有了... HOHO,楼上的朋友真会送帽子,一顶又一顶~~~ 就是我同意microcat() 的观点,现在的这些程序员素质太差,给他要代码跟要他命似的 建议研究一下Adobe Photoshop的ActiveX文件,调用它! microcat 呵呵,没必要那么说 RT,要求转换后图像的大小可以设定,图像的质量也可以调节,怎么样实现,我研究了好几天了,但没有搞定,请各位大侠帮忙!!-----------------------------------------------------去找一本书,名字叫<<图像格式大全>>,里面介绍有暴多的图像格式,而且记得对编码解码的原理都有很详细的介绍。如果你要完成所需,最好备此部头一本。主要流程为:A.将所有格式转换为标准的32位bmp B.如此如此,这般这般,调节大小等等。 C.按照你所理解的jpg编码来压缩吧,这是有损压缩,图像质量是可调的 D.剩下全看你的毅力了,祝你好运! jpg.CompressionQuality取值1..100,控制JPG的压缩质量 搞定,在GraphicEx的基础上...unit UnitDllFunc;interfaceuses Graphics, Jpeg, GraphicEx; function ConvertPICintoJPG( cPic :TPicture; //需要变换的图形 jQuality :Integer; //变换后JPEG图像的压缩质量(1..100为有效值) pWidth :Integer = 0; //变换后JPEG图像的宽度(大于0为有效值,否则不改变宽度) pHeight :Integer = 0 //变换后JPEG图像的高度(大于0为有效值,否则不改变高度) ): TJpegImage; stdcall; function ConvertPICintoBMP( cPic :TPicture; //需要变换的图形 PixelBit :Integer; //变换后BMP图像的位数(1..6为有效值) pWidth :Integer = 0; //变换后BMP图像的宽度(大于0为有效值,否则不改变宽度) pHeight :Integer = 0 //变化后BMP图像的高度(大于0为有效值,否则不改变高度) ): TBitmap; stdcall;implementation//其他图片格式转成JPG格式function ConvertPICintoJPG(cPic: TPicture; jQuality: Integer; pWidth: Integer = 0; pHeight: Integer = 0): TJpegImage; stdcall;var tBMP: TBitmap;begin Result := TJpegImage.Create; if (pWidth > 0) or (pHeight > 0) then begin try tBMP := TBitmap.Create; //创建一个过渡性BMP图片,用于更改图片尺寸 if pWidth <= 0 then pWidth := cPic.Width; //若pWidth为有效值则改变tBMP宽度,否则不变 if pHeight <= 0 then pHeight := cPic.Height; //若pHeight为有效值则改变tBMP高度,否则不变 tBMP.Width := pWidth; tBMP.Height := pHeight; tBMP.Canvas.StretchDraw(tBMP.Canvas.ClipRect, cPic.Graphic); //按照新尺寸重画图形 Result.Assign(tBMP); finally tBMP.Free; end;//try Create tBMP end else Result.Assign(cPic); //if //设置压缩质量 if jQuality in [1..100] then Result.CompressionQuality := jQuality;end;//其他图片格式转成BMP格式function ConvertPICintoBMP(cPic: TPicture; PixelBit: Integer; pWidth: Integer = 0; pHeight: Integer = 0): TBitmap; stdcall;begin Result := TBitmap.Create; if (pWidth > 0) or (pHeight > 0) then begin if pWidth <= 0 then pWidth := cPic.Width; //若pWidth为有效值则改变tBMP宽度,否则不变 if pHeight <= 0 then pHeight := cPic.Height; //若pHeight为有效值则改变tBMP高度,否则不变 Result.Width := pWidth; Result.Height := pHeight; Result.Canvas.StretchDraw(Result.Canvas.ClipRect, cPic.Graphic); //按照新尺寸重画图形 end else Result.Assign(cPic); //设置BMP图片的位数 case PixelBit of 1: Result.PixelFormat := pf1bit; //2色 2: Result.PixelFormat := pf4bit; //8色 3: Result.PixelFormat := pf8bit; //256色 4: Result.PixelFormat := pf15bit; //64K色 5: Result.PixelFormat := pf24bit; //16M色 6: Result.PixelFormat := pf32bit; //16M+色 end;end;end. 这是写在dll中的代码,所以有stdcall 函数有问题,当改写为function ConvertPICintoBMP(cPic: TPicture; PixelBit, pWidth, pHeight: Integer): TBitmap;begin Result := TBitmap.Create; if (pWidth > 0) or (pHeight > 0) then begin Result.Width := pWidth; Result.Height := pHeight; end else begin Result.Width := cPic.Width; Result.Height := cPic.Height; end; Result.Canvas.StretchDraw(Result.Canvas.ClipRect, cPic.Graphic); //按照新尺寸重画图形 //设置BMP图片的位数 case PixelBit of 1: Result.PixelFormat := pf1bit; //2色 2: Result.PixelFormat := pf4bit; //8色 3: Result.PixelFormat := pf8bit; //256色 4: Result.PixelFormat := pf15bit; //64K色 5: Result.PixelFormat := pf24bit; //16M色 6: Result.PixelFormat := pf32bit; //16M+色 end;end; 不知道Delphi对GDI+的支持怎么样,用GDI+内建的编解码器可以支持JPG/BMP/PNG/TIF之间的转换 呵呵,Delphi通过JEDI的GDI+库就能使用啦:)这个是JPG To BMP的,要别的格式原理也是一样的unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, GDIPAPI, GDIPOBJ, GDIPUTIL;type TForm1 = class(TForm) Memo1: TMemo; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);var encoderClsid: TGUID; stat: TStatus; Image: TGPImage;begin // Get a JPEG image from the disk. Image := TGPImage.Create('..\..\Media\FRUIT.JPG'); // Get the CLSID of the Bitmap encoder. GetEncoderClsid('image/bmp', encoderClsid);//这里设置格式! TGPBitmap(image).SetResolution(96, 96); stat := image.Save('HighRes.bmp', encoderClsid); if(stat = Ok) then memo1.Lines.Add('HighRes.bmp saved successfully.') else memo1.Lines.Add(GetStatus(Stat) + ' Attempt to save HighRes.bmp failed.'); image.Free;end;end.http://lysoft.7u7.net 处理日期型数据 高分求助!!BDS2006中如何升级INDY10 开发仪器仪表软件,请大家给些意见 [:(!]声明动态库函数,调用总是不成功,应该是那里的问题。望大家帮助。 关于制作安装程序的问题?? 关于在dll实现窗体重用问题 我想考程序员,会考哪些科目? 字符串替换函数是什么? 。。。如何判定maskedit是否输入了相关的内容????<===== 如果代码行语句中用到了关键字,这样代码专家辅助助手就不能调出来了,有什么办法吗?求高手解之。 请大家帮忙看一下下面关于COMBoBoxEx.data使用的代码怎么回事? 打包
-----------------------------------------------------
去找一本书,名字叫<<图像格式大全>>,里面介绍有暴多的图像格式,而且记得对编码解码的原理
都有很详细的介绍。如果你要完成所需,最好备此部头一本。
主要流程为:A.将所有格式转换为标准的32位bmp
B.如此如此,这般这般,调节大小等等。
C.按照你所理解的jpg编码来压缩吧,这是有损压缩,图像质量是可调的
D.剩下全看你的毅力了,祝你好运!
unit UnitDllFunc;interfaceuses Graphics, Jpeg, GraphicEx; function ConvertPICintoJPG(
cPic :TPicture; //需要变换的图形
jQuality :Integer; //变换后JPEG图像的压缩质量(1..100为有效值)
pWidth :Integer = 0; //变换后JPEG图像的宽度(大于0为有效值,否则不改变宽度)
pHeight :Integer = 0 //变换后JPEG图像的高度(大于0为有效值,否则不改变高度)
): TJpegImage; stdcall;
function ConvertPICintoBMP(
cPic :TPicture; //需要变换的图形
PixelBit :Integer; //变换后BMP图像的位数(1..6为有效值)
pWidth :Integer = 0; //变换后BMP图像的宽度(大于0为有效值,否则不改变宽度)
pHeight :Integer = 0 //变化后BMP图像的高度(大于0为有效值,否则不改变高度)
): TBitmap; stdcall;implementation//其他图片格式转成JPG格式
function ConvertPICintoJPG(cPic: TPicture; jQuality: Integer;
pWidth: Integer = 0; pHeight: Integer = 0): TJpegImage; stdcall;
var
tBMP: TBitmap;
begin
Result := TJpegImage.Create; if (pWidth > 0) or (pHeight > 0) then
begin
try
tBMP := TBitmap.Create; //创建一个过渡性BMP图片,用于更改图片尺寸
if pWidth <= 0 then pWidth := cPic.Width; //若pWidth为有效值则改变tBMP宽度,否则不变
if pHeight <= 0 then pHeight := cPic.Height; //若pHeight为有效值则改变tBMP高度,否则不变
tBMP.Width := pWidth;
tBMP.Height := pHeight;
tBMP.Canvas.StretchDraw(tBMP.Canvas.ClipRect, cPic.Graphic); //按照新尺寸重画图形
Result.Assign(tBMP);
finally
tBMP.Free;
end;//try Create tBMP
end
else Result.Assign(cPic); //if //设置压缩质量
if jQuality in [1..100] then Result.CompressionQuality := jQuality;
end;//其他图片格式转成BMP格式
function ConvertPICintoBMP(cPic: TPicture; PixelBit: Integer;
pWidth: Integer = 0; pHeight: Integer = 0): TBitmap; stdcall;
begin
Result := TBitmap.Create; if (pWidth > 0) or (pHeight > 0) then
begin
if pWidth <= 0 then pWidth := cPic.Width; //若pWidth为有效值则改变tBMP宽度,否则不变
if pHeight <= 0 then pHeight := cPic.Height; //若pHeight为有效值则改变tBMP高度,否则不变
Result.Width := pWidth;
Result.Height := pHeight;
Result.Canvas.StretchDraw(Result.Canvas.ClipRect, cPic.Graphic); //按照新尺寸重画图形
end
else Result.Assign(cPic); //设置BMP图片的位数
case PixelBit of
1: Result.PixelFormat := pf1bit; //2色
2: Result.PixelFormat := pf4bit; //8色
3: Result.PixelFormat := pf8bit; //256色
4: Result.PixelFormat := pf15bit; //64K色
5: Result.PixelFormat := pf24bit; //16M色
6: Result.PixelFormat := pf32bit; //16M+色
end;
end;end.
function ConvertPICintoBMP(cPic: TPicture; PixelBit, pWidth,
pHeight: Integer): TBitmap;
begin
Result := TBitmap.Create; if (pWidth > 0) or (pHeight > 0) then
begin
Result.Width := pWidth;
Result.Height := pHeight;
end
else
begin
Result.Width := cPic.Width;
Result.Height := cPic.Height;
end;
Result.Canvas.StretchDraw(Result.Canvas.ClipRect, cPic.Graphic); //按照新尺寸重画图形 //设置BMP图片的位数
case PixelBit of
1: Result.PixelFormat := pf1bit; //2色
2: Result.PixelFormat := pf4bit; //8色
3: Result.PixelFormat := pf8bit; //256色
4: Result.PixelFormat := pf15bit; //64K色
5: Result.PixelFormat := pf24bit; //16M色
6: Result.PixelFormat := pf32bit; //16M+色
end;
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, GDIPAPI, GDIPOBJ, GDIPUTIL;type
TForm1 = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
encoderClsid: TGUID;
stat: TStatus;
Image: TGPImage;
begin
// Get a JPEG image from the disk.
Image := TGPImage.Create('..\..\Media\FRUIT.JPG'); // Get the CLSID of the Bitmap encoder.
GetEncoderClsid('image/bmp', encoderClsid);//这里设置格式! TGPBitmap(image).SetResolution(96, 96);
stat := image.Save('HighRes.bmp', encoderClsid); if(stat = Ok) then
memo1.Lines.Add('HighRes.bmp saved successfully.')
else
memo1.Lines.Add(GetStatus(Stat) + ' Attempt to save HighRes.bmp failed.'); image.Free;
end;end.http://lysoft.7u7.net