如何利用delphi编辑wmf格式图像及如何旋转显示wmf ( 积分: 300 )

  • 主题发起人 主题发起人 马洪波
  • 开始时间 开始时间

马洪波

Unregistered / Unconfirmed
GUEST, unregistred user!
如何利用delphi编辑wmf格式图像,最好有现成免费控件
及如何旋转显示wmf
 
如何利用delphi编辑wmf格式图像,最好有现成免费控件
及如何旋转显示wmf
 
好,帮顶



--------签名档---------------------------

比肩国内顶尖源码下载站点 -> 源码我爱你

http://www.source520.com
http://www.source520.net

80G源码电子书免费免注册下载,大量精辟技术文档库随时更新
******************************************************************
附:为了站点持续发展,现有本站近年来收藏的大量大型商业源码低价出售,
详情请进入以下链接查看:
http://www.source520.com/building_delphi.htm

浏览商业代码请从如下URL进入查看实物:
1.商业源码库1: ftp://source520see3:browse@61.152.199.245/
2.商业源码库2: ftp://source520see2:browse@61.152.199.245/
 
这个好象自己做不到,或者说成本很高.使用ole不行吗?
 
文件记录的是绘图命令(包括坐标),如果旋转里面的图,要读出坐标,在根据绘图函数画图,恐怕rectangle 之类的就不容易了,还得自己画,我想不如把文件庄化为位图旋转,
旋转wmf图我觉得没神马意义,如果只为让他作为记录文件做适量图,不如自定义纪录文件
 
使用Ole怎么做啊?
请 东问西答 给个例子吧!
 
unit EMFTransform;

interface
uses
Classes, Windows;

procedure TransformEMF(emf: HENHMETAFILE; DoRotate, DoFlip, DoMirror: boolean);

implementation
uses
SysUtils, Dialogs;

var
centerl: TPoint;
Rotate, Flip, Mirror: boolean;


{------------------------------------------------------------------------------}
function SmallPoint(x, y: SHORT): TSmallPoint;
begin
Result.x:= x;
Result.y:= y;
end;

{------------------------------------------------------------------------------}
function RectCenter(rec: TRect): TPoint;
begin
result:= Point((rec.Left + rec.Right) div 2, (rec.Top + rec.Bottom) div 2);
end;

{------------------------------------------------------------------------------}
procedure InvertHVRect(var rec: TRect);
var
tmp: LongInt;
begin
tmp:= rec.Left;
rec.Left:= rec.Top;
rec.Top:= tmp;
tmp:= rec.Right;
rec.Right:= rec.Bottom;
rec.Bottom:= tmp;
end;

{------------------------------------------------------------------------------}
procedure InvertHVPoint(var pt: TPoint);
var
tmp: LongInt;
begin
tmp:= pt.X;
pt.X:= pt.Y;
pt.Y:= tmp;
end;

{------------------------------------------------------------------------------}
procedure RotatePoint(var pt: TPoint; center: TPoint);
begin
pt:= Point(pt.Y, 2*center.X - pt.X);
end;

{------------------------------------------------------------------------------}
procedure FlipPoint(var pt: TPoint; center: TPoint);
// Le haut deviens le bas et inversement
begin
pt:= Point(pt.X, 2*center.Y - pt.Y);
end;

{------------------------------------------------------------------------------}
procedure MirrorPoint(var pt: TPoint; center: TPoint);
// La gauche devient la droite et inversement
begin
pt:= Point(2*center.X - pt.X, pt.Y);
end;

{------------------------------------------------------------------------------}
procedure RotateSmallPoint(var pt: TSmallPoint; center: TPoint);
begin
pt:= SmallPoint(pt.Y, 2*center.X - pt.X);
end;

{------------------------------------------------------------------------------}
procedure FlipSmallPoint(var pt: TSmallPoint; center: TPoint);
// Le haut deviens le bas et inversement
begin
pt:= SmallPoint(pt.X, 2*center.Y - pt.Y);
end;

{------------------------------------------------------------------------------}
procedure MirrorSmallPoint(var pt: TSmallPoint; center: TPoint);
// La gauche devient la droite et inversement
begin
pt:= SmallPoint(2*center.X - pt.X, pt.Y);
end;

{------------------------------------------------------------------------------}
procedure RotateRect(var r: TRect; center: TPoint);
var
p2, p4: TPoint;
begin
p2:= Point(r.Right, r.Top);
p4:= Point(r.Left, r.Bottom);
RotatePoint(p2, Center);
RotatePoint(p4, Center);
r:= Rect(p2.X, p2.Y, p4.X, p4.Y);
end;

{------------------------------------------------------------------------------}
procedure FlipRect(var r: TRect; center: TPoint);
var
p1, p2: TPoint;
begin
p1:= r.TopLeft;
p2:= r.BottomRight;
FlipPoint(p1, center);
FlipPoint(p2, center);
r.Top:= p2.Y;
r.Bottom:= p1.Y;
end;

{------------------------------------------------------------------------------}
procedure MirrorRect(var r: TRect; center: TPoint);
var
p1, p2: TPoint;
begin
p1:= r.TopLeft;
p2:= r.BottomRight;
MirrorPoint(p1, center);
MirrorPoint(p2, center);
r.Left:= p2.X;
r.Right:= p1.X;
end;

{------------------------------------------------------------------------------}
procedure RotateSize(var sz: TSize);
var
tmpl: LongInt;
begin
tmpl:= sz.cx;
sz.cx:= sz.cy;
sz.cy:= tmpl;
end;

{------------------------------------------------------------------------------}
function EnhMetaFileProc_Manipulate(DC: HDC; lpHTable: PHandleTable; lpEMFR: PENHMetaRecord; nObj: integer; lpData: LPARAM): integer; stdcall;
var
i: integer;
begin
Result:= 1;

case lpEMFR^.iType of
EMR_HEADER:
with PEnhMetaHeader(lpEMFR)^ do
begin
if Rotate then
begin
InvertHVRect(PEnhMetaHeader(lpEMFR)^.rclBounds);
InvertHVRect(PEnhMetaHeader(lpEMFR)^.rclFrame);

RotateSize(PEnhMetaHeader(lpEMFR)^.szlDevice);
RotateSize(PEnhMetaHeader(lpEMFR)^.szlMillimeters);
end;
end;

EMR_LINETO, EMR_MOVETOEX:
begin
if Rotate then
RotatePoint(PEMRLineTo(lpEMFR)^.ptl, centerl);
if Flip then
FlipPoint(PEMRLineTo(lpEMFR)^.ptl, centerl);
if Mirror then
MirrorPoint(PEMRLineTo(lpEMFR)^.ptl, centerl);
end;

EMR_OFFSETCLIPRGN:
begin
if Rotate then
RotatePoint(PEMROffsetClipRgn(lpEMFR)^.ptlOffset, centerl);
if Flip then
FlipPoint(PEMROffsetClipRgn(lpEMFR)^.ptlOffset, centerl);
if Mirror then
MirrorPoint(PEMROffsetClipRgn(lpEMFR)^.ptlOffset, centerl);
end;

EMR_FILLPATH, EMR_STROKEANDFILLPATH, EMR_STROKEPATH:
begin
if Rotate then
RotateRect(PEMRFillPath(lpEMFR)^.rclBounds, centerl);
if Flip then
FlipRect(PEMRFillPath(lpEMFR)^.rclBounds, centerl);
if Mirror then
MirrorRect(PEMRFillPath(lpEMFR)^.rclBounds, centerl);
end;

EMR_EXCLUDECLIPRECT, EMR_INTERSECTCLIPRECT:
begin
if Rotate then
RotateRect(PEMRExcludeClipRect(lpEMFR)^.rclClip, centerl);
if Flip then
FlipRect(PEMRExcludeClipRect(lpEMFR)^.rclClip, centerl);
if Mirror then
MirrorRect(PEMRExcludeClipRect(lpEMFR)^.rclClip, centerl);
end;

EMR_SETWINDOWORGEX:
with PEMRSetViewportOrgEx(lpEMFR)^ do
begin
// Nothing
end;


EMR_SETVIEWPORTORGEX, EMR_SETBRUSHORGEX:
with PEMRSetViewportOrgEx(lpEMFR)^ do
begin
// Nothing
end;

EMR_SETVIEWPORTEXTEX, EMR_SETWINDOWEXTEX:
begin
// Nothing
end;

EMR_SETPIXELV:
begin
if Rotate then
RotatePoint(PEMRSetPixelV(lpEMFR)^.ptlPixel, centerl);
if Flip then
FlipPoint(PEMRSetPixelV(lpEMFR)^.ptlPixel, centerl);
if Mirror then
MirrorPoint(PEMRSetPixelV(lpEMFR)^.ptlPixel, centerl);
end;

EMR_EXTFLOODFILL:
begin
if Rotate then
RotatePoint(PEMRExtFloodFill(lpEMFR)^.ptlStart, centerl);
if Flip then
FlipPoint(PEMRExtFloodFill(lpEMFR)^.ptlStart, centerl);
if Mirror then
MirrorPoint(PEMRExtFloodFill(lpEMFR)^.ptlStart, centerl);
end;

EMR_ELLIPSE, EMR_RECTANGLE:
begin
if Rotate then
RotateRect(PEMREllipse(lpEMFR)^.rclBox, centerl);
if Flip then
FlipRect(PEMREllipse(lpEMFR)^.rclBox, centerl);
if Mirror then
MirrorRect(PEMREllipse(lpEMFR)^.rclBox, centerl);
end;

EMR_ROUNDRECT:
begin
if Rotate then
begin
RotateRect(PEMRRoundRect(lpEMFR)^.rclBox, centerl);
RotateSize(PEMRRoundRect(lpEMFR)^.szlCorner);
end;
if Flip then
FlipRect(PEMRRoundRect(lpEMFR)^.rclBox, centerl);
if Mirror then
MirrorRect(PEMRRoundRect(lpEMFR)^.rclBox, centerl);
end;

EMR_ARC, EMR_ARCTO, EMR_CHORD, EMR_PIE:
begin
if Rotate then
begin
RotateRect(PEMRArc(lpEMFR)^.rclBox, centerl);
RotatePoint(PEMRArc(lpEMFR)^.ptlStart, centerl);
RotatePoint(PEMRArc(lpEMFR)^.ptlEnd, centerl);
end;
if Flip then
begin
FlipRect(PEMRArc(lpEMFR)^.rclBox, centerl);
FlipPoint(PEMRArc(lpEMFR)^.ptlStart, centerl);
FlipPoint(PEMRArc(lpEMFR)^.ptlEnd, centerl);
end;
if Mirror then
begin
MirrorRect(PEMRArc(lpEMFR)^.rclBox, centerl);
MirrorPoint(PEMRArc(lpEMFR)^.ptlStart, centerl);
MirrorPoint(PEMRArc(lpEMFR)^.ptlEnd, centerl);
end;
end;

EMR_ANGLEARC:
begin
if Rotate then
RotatePoint(PEMRAngleArc(lpEMFR)^.ptlcenter, centerl);
if Flip then
FlipPoint(PEMRAngleArc(lpEMFR)^.ptlcenter, centerl);
if Mirror then
MirrorPoint(PEMRAngleArc(lpEMFR)^.ptlcenter, centerl);
end;

EMR_POLYLINE, EMR_POLYBEZIER, EMR_POLYGON, EMR_POLYBEZIERTO, EMR_POLYLINETO:
begin
if Rotate then
RotateRect(PEMRPolyline(lpEMFR)^.rclBounds, centerl);
if Flip then
FlipRect(PEMRPolyline(lpEMFR)^.rclBounds, centerl);
if Mirror then
MirrorRect(PEMRPolyline(lpEMFR)^.rclBounds, centerl);
for i:=0 to PEMRPolyline(lpEMFR)^.cptl-1 do
begin
if Rotate then
RotatePoint(PEMRPolyline(lpEMFR)^.aptl, Centerl);
if Flip then
FlipPoint(PEMRPolyline(lpEMFR)^.aptl, Centerl);
if Mirror then
MirrorPoint(PEMRPolyline(lpEMFR)^.aptl, Centerl);
end;
end;

EMR_POLYLINE16, EMR_POLYBEZIER16, EMR_POLYGON16, EMR_POLYBEZIERTO16, EMR_POLYLINETO16:
begin
if Rotate then
RotateRect(PEMRPolyline16(lpEMFR)^.rclBounds, centerl);
if Flip then
FlipRect(PEMRPolyline16(lpEMFR)^.rclBounds, centerl);
if Mirror then
MirrorRect(PEMRPolyline16(lpEMFR)^.rclBounds, centerl);
for i:=0 to PEMRPolyline16(lpEMFR)^.cpts-1 do
begin
if Rotate then
RotateSmallPoint(PEMRPolyline16(lpEMFR)^.apts, Centerl);
if Flip then
FlipSmallPoint(PEMRPolyline16(lpEMFR)^.apts, Centerl);
if Mirror then
MirrorSmallPoint(PEMRPolyline16(lpEMFR)^.apts, Centerl);
end;
end;

EMR_POLYDRAW:
begin
if Rotate then
RotateRect(PEMRPolyDraw(lpEMFR)^.rclBounds, centerl);
if Flip then
FlipRect(PEMRPolyDraw(lpEMFR)^.rclBounds, centerl);
if Mirror then
MirrorRect(PEMRPolyDraw(lpEMFR)^.rclBounds, centerl);
for i:=0 to PEMRPolyDraw(lpEMFR)^.cptl-1 do
begin
if Rotate then
RotatePoint(PEMRPolyDraw(lpEMFR)^.aptl, Centerl);
if Flip then
FlipPoint(PEMRPolyDraw(lpEMFR)^.aptl, Centerl);
if Mirror then
MirrorPoint(PEMRPolyDraw(lpEMFR)^.aptl, Centerl);
end;
end;

EMR_POLYDRAW16:
begin
if Rotate then
RotateRect(PEMRPolyDraw16(lpEMFR)^.rclBounds, centerl);
if Flip then
FlipRect(PEMRPolyDraw16(lpEMFR)^.rclBounds, centerl);
if Mirror then
MirrorRect(PEMRPolyDraw16(lpEMFR)^.rclBounds, centerl);
for i:=0 to PEMRPolyDraw16(lpEMFR)^.cpts-1 do
begin
if Rotate then
RotateSmallPoint(PEMRPolyDraw16(lpEMFR)^.apts, Centerl);
if Flip then
FlipSmallPoint(PEMRPolyDraw16(lpEMFR)^.apts, Centerl);
if Mirror then
MirrorSmallPoint(PEMRPolyDraw16(lpEMFR)^.apts, Centerl);
end;
end;

EMR_POLYPOLYLINE, EMR_POLYPOLYGON:
begin
if Rotate then
RotateRect(PEMRPolyPolyLine(lpEMFR)^.rclBounds, centerl);
if Flip then
FlipRect(PEMRPolyPolyLine(lpEMFR)^.rclBounds, centerl);
if Mirror then
MirrorRect(PEMRPolyPolyLine(lpEMFR)^.rclBounds, centerl);
for i:=0 to PEMRPolyPolyLine(lpEMFR)^.cptl-1 do
begin
if Rotate then
RotatePoint(PEMRPolyPolyLine(lpEMFR)^.aptl, Centerl);
if Flip then
FlipPoint(PEMRPolyPolyLine(lpEMFR)^.aptl, Centerl);
if Mirror then
MirrorPoint(PEMRPolyPolyLine(lpEMFR)^.aptl, Centerl);
end;
end;

EMR_POLYPOLYLINE16, EMR_POLYPOLYGON16:
begin
if Rotate then
RotateRect(PEMRPolyPolyLine16(lpEMFR)^.rclBounds, centerl);
if Flip then
FlipRect(PEMRPolyPolyLine16(lpEMFR)^.rclBounds, centerl);
if Mirror then
MirrorRect(PEMRPolyPolyLine16(lpEMFR)^.rclBounds, centerl);
for i:=0 to PEMRPolyPolyLine16(lpEMFR)^.cpts-1 do
begin
if Rotate then
RotateSmallPoint(PEMRPolyPolyLine16(lpEMFR)^.apts, Centerl);
if Flip then
FlipSmallPoint(PEMRPolyPolyLine16(lpEMFR)^.apts, Centerl);
if Mirror then
MirrorSmallPoint(PEMRPolyPolyLine16(lpEMFR)^.apts, Centerl);
end;
end;

EMR_EXTSELECTCLIPRGN:
begin
//Nothing
end;

EMR_SCALEVIEWPORTEXTEX, EMR_SCALEWINDOWEXTEX, EMR_SETWORLDTRANSFORM,
EMR_MODIFYWORLDTRANSFORM, EMR_INVERTRGN, EMR_PAINTRGN, EMR_FILLRGN,
EMR_FRAMERGN, EMR_EXTTEXTOUTA, EMR_EXTTEXTOUTW,
EMR_POLYTEXTOUTA, EMR_POLYTEXTOUTW :
begin
// Nothing
end;
end;
end;

procedure TransformEMF(emf: HENHMETAFILE; DoRotate, DoFlip, DoMirror: boolean);
var
metaHeader: TEnhMetaHeader;
begin
Rotate:= DoRotate;
Flip:= DoFlip;
Mirror:= DoMirror;
GetEnhMetaFileHeader(emf, SizeOf(TEnhMetaHeader), @metaHeader);
with metaHeader do
centerl:= Point((rclBounds.Left + rclBounds.Right) div 2,
(rclBounds.Top + rclBounds.Bottom) div 2);
EnumEnhMetaFile(0, emf, @EnhMetaFileProc_Manipulate, nil, Rect(0, 0, 0, 0));
end;


end.
 
上面是旋转的代码,编辑就太复杂了,相当于写个CAD了,没有一个月以上时间是做不出来的,就算有人写出来了也不会随便给人吧,呵呵!
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部