在delphi中怎么样把JPEG,bmp,png,tif等格式文件转换为JPG

xiaoyutianzi 2004-11-19 05:09:06
RT,要求转换后图像的大小可以设定,图像的质量也可以调节,怎么样实现,我研究了好几天了,但没有搞定,请各位大侠帮忙!!
...全文
2106 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
ly_liuyang 2004-12-15
  • 打赏
  • 举报
回复
呵呵,Delphi通过JEDI的GDI+库就能使用啦:)

这个是JPG To BMP的,要别的格式原理也是一样的
unit Unit1;

interface

uses
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
类库 2004-12-15
  • 打赏
  • 举报
回复
不知道Delphi对GDI+的支持怎么样,用GDI+内建的编解码器可以支持JPG/BMP/PNG/TIF之间的转换
xx_adam 2004-12-15
  • 打赏
  • 举报
回复
ding
xx_adam 2004-12-15
  • 打赏
  • 举报
回复
ding
ehom 2004-12-15
  • 打赏
  • 举报
回复
GDI+对PNG和TIFF的支持不好
mmc0531 2004-12-14
  • 打赏
  • 举报
回复
函数有问题,当改写为
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;
king20151111 2004-12-02
  • 打赏
  • 举报
回复
真是不错呀
hhnick 2004-12-02
  • 打赏
  • 举报
回复
受益呀。
zzlingaaa 2004-11-24
  • 打赏
  • 举报
回复
这是写在dll中的代码,所以有stdcall
zzlingaaa 2004-11-24
  • 打赏
  • 举报
回复
搞定,在GraphicEx的基础上...
unit UnitDllFunc;

interface

uses 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.
xiexy 2004-11-24
  • 打赏
  • 举报
回复
很多现成的控件
fronm 2004-11-23
  • 打赏
  • 举报
回复
哈哈,关注一下动态
zzlingaaa 2004-11-23
  • 打赏
  • 举报
回复
jpg.CompressionQuality取值1..100,控制JPG的压缩质量
TOMWLD 2004-11-22
  • 打赏
  • 举报
回复
晕,不劳而获还振振有词
tuqvb 2004-11-21
  • 打赏
  • 举报
回复
RT,要求转换后图像的大小可以设定,图像的质量也可以调节,怎么样实现,我研究了好几天了,但没有搞定,请各位大侠帮忙!!
-----------------------------------------------------
去找一本书,名字叫<<图像格式大全>>,里面介绍有暴多的图像格式,而且记得对编码解码的原理
都有很详细的介绍。如果你要完成所需,最好备此部头一本。
主要流程为:A.将所有格式转换为标准的32位bmp
B.如此如此,这般这般,调节大小等等。
C.按照你所理解的jpg编码来压缩吧,这是有损压缩,图像质量是可调的
D.剩下全看你的毅力了,祝你好运!
nyf1220 2004-11-21
  • 打赏
  • 举报
回复
microcat 呵呵,没必要那么说
tuqvb 2004-11-21
  • 打赏
  • 举报
回复
中国的程序员素质实在太低,你搞了好几年才搞定,也要别人用好几年来搞定?
说说你的研究成果会把你累死,还是会抢走你的饭碗?

中国的重复建设为什么多,原因一目了然,象你这种人要当了官也就是出腐败工程的料
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(还好你不是),鄙视你!!!
别人不是在求你回答问题,象你这种垃圾应该滚出CSDN...
~~~~~~~~~~~~~~~~~~~~~~~~~~~
我不懂,但我支持楼主,帮顶
--------------------------------------------------------------
呵呵,好有型有素养的样子。
既然别人是研究了几年才完全搞定的东西,你认为在一个帖子里能完全给你解释清楚么?
要知道,看白书是没有人权的,首先自己要虚心。
而且别人可以讲给你听,也可以不讲给你听。
就像你不可能要求百万富翁分你点钱一样,没有人有义务给你优待。

且不说jpg的熵编码方式就有好多种,而且其中的原理还包括很多方面的知识
例如离散数学,信息论,各种变换的基础等等。而且png,tiff格式的细节就足
以出本手册咳咳,只言片语怎么说得清楚。
再说ehom老兄已经给你指出了一条在几天内搞定的光明大道
如果你真的想几天内就完工,只能如此了
老本 2004-11-21
  • 打赏
  • 举报
回复
建议研究一下Adobe Photoshop的ActiveX文件,调用它!
wsh1688 2004-11-21
  • 打赏
  • 举报
回复
就是我同意microcat() 的观点,现在的这些程序员素质太差,给他要代码跟要他命似的
ehom 2004-11-19
  • 打赏
  • 举报
回复
HOHO,楼上的朋友真会送帽子,一顶又一顶~~~
加载更多回复(2)
GraphicEx is an addendum to Delphi's Graphics.pas in order to enable your application to load many common image formats. This library is primarily designed to load images as background (buttons, forms, toolbars) and textures (DirectX, OpenGL) or for image browsing and editing purposes as long as you don't need to save images. Currently only TTargaGraphic also supports saving an image. GraphicEx is open source under the Mozilla Public License (MPL). Please read the license agreement before you start using this library. TIFF images (*.tif; *.tiff), extended base line implementation byte orders: little endian, big endian sample sizes: 1, 2, 4, 8, 16 bits per sample color spaces: indexed, grayscale, RGB(A), CMYK, L*a*b* compression formats: uncompressed, packed bits, LZW, CCITT T.4 (raw and modified fax group 3, possibly word aligned), ThunderScan, Deflate, new style JPEG GFI fax images (*.fax), uses TTIFFGraphic to read sample size: 1 bits per sample color space: indexed compression format: CCITT T.4 (raw and modified fax group 3) SGI images (*.bw, *.rgb, *.rgba, *.sgi) byte order: big endian sample sizes: 1, 2, 4, 8, 16 bits per sample color spaces: indexed, grayscale, RGB(A) compression formats: uncompressed, RLE Autodesk images files (*.cel; *.pic) old style only byte order: little endian sample size: 8 bits per sample color spaces: indexed compression format: uncompressed Truevision images (*.tga; *.vst; *.icb; *.vda; *.win), write support included byte order: little endian sample sizes: 5, 8 bits per sample color spaces: gray scale, indexed, 15 bits RGB (555), 24 bits RGB(A)(888) compression formats: uncompressed, RLE ZSoft Paintbrush images (*.pcx, *.pcc) byte order: little endian sample sizes: 1, 2, 4, 8 bits per sample color spaces: gray scale, indexed, RGB compression formats: uncompressed, RLE Word 5.x screen capture files (*.scr) byte order: little endian sample sizes: 1, 2, 4, 8 bits per sample color spaces: indexed, gray scaleRGB compression formats: uncompressed, RLE Kodak Photo-CD images (*.pcd) byte order: little endian samples size: 8 bits per sample color space: YCbCr compression: PCD Huffmann specials: sizes: all resolutions, from 192 x 128 up to 6144 x 4096 (64 Base vaporware) rotated: clockwise and counter-clockwise Portable pixel/gray map images (*.ppm, *.pgm, *.pbm) byte order: little endian sample sizes: 1, 8 bits per sample color spaces: gray scale, indexed, RGB compression format: uncompressed specials: ASCII and Binary format Dr. Halo images (*.cut, *.pal) byte order: little endian sample size: 8 bits per sample color spaces: indexed compression formats: RLE special: external palette file (*.pal) is automatically loaded when specified while doing LoadFromStream or when loading the image via LoadFromFile CompuServe images (*.gif) byte order: little endian sample sizes: 1, 4, 8 bits per sample color spaces: indexed compression format: LZW special: interlaced, non-interlaced SGI Wavefront images (*.rla, *.rpf) byte order: big endian sample size: 8 bits per sample color space: RGB(A) compression formats: RLE Standard Windows bitmap images (*.bmp, *.rle, *.dib), these formats are natively supported by Delphi's VCL but *.rle and *.dib files are not registered with TPicture by default byte order: little endian sample sizes: 1, 4, 8 bits per sample color spaces: indexed, RGB(A) compression formats: uncompressed, RLE specials: OS/2 bitmap format Photoshop images (*.psd, *.pdd) byte order: big endian sample sizes: 1, 8, 16 bits per sample color spaces: indexed, RGB, CMYK, CIE L*a*b* compression formats: uncompressed, packed bits special: duo tone Paintshop Pro images (*.psp) byte order: little endian sample sizes: 1, 4, 8 bits per sample color spaces: indexed, gray scale, RGB compression formats: uncompressed, LZ77 Portable network graphic images (*.png) byte order: big endian sample sizes: 1, 2, 4, 8, 16 bits per sample color spaces: indexed, grayscale (alpha), RGB(A) compression format: LZ77 specials: supported chunks: IHDR, IDAT, IEND, PLTE, gAMA, tRNS, bKGD transparency support partially for RGB, which is stored as 32 bits format

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi GAME,图形处理/多媒体
社区管理员
  • GAME,图形处理/多媒体社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧