RT,要求转换后图像的大小可以设定,图像的质量也可以调节,怎么样实现,我研究了好几天了,但没有搞定,请各位大侠帮忙!!
解决方案 »
- 关于窗口中控件坐标和控件句柄的问题
- 怎样查看到QQ空间个人日志的源代码???
- Delphi初学者应小心的六大陷阱
- ACCESS中的日期问题
- delphi的入口主函数,求助
- license information from TMScomm not found,you cannot use this control in design mode?
- 局部函数和全局函数是如何定义的?跟局部过程和全局过程的定义是否有所差异?
- Delphi 与 VC++
- 简单的ado事务
- 告--------- CSDN 数据库 管理员----------书
- 请大家帮忙看一下下面关于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