问一下朋友们对图片比例缩放的问题,非常有意思, ( 积分: 200 )

  • 主题发起人 主题发起人 coolmoon007
  • 开始时间 开始时间
C

coolmoon007

Unregistered / Unconfirmed
GUEST, unregistred user!
请教你一个关于图片比例放缩的问题,比如一个平面640*480的图片,我现在要内贴到一个立体物体中,站在立体内部看图片,比如说正方体中,画在内贴过程中比例会出现不协调,怎么可以处理一下使比例能和原来的一致,咋可以解决这个问题?如果立体图形改成别的?
 
请教你一个关于图片比例放缩的问题,比如一个平面640*480的图片,我现在要内贴到一个立体物体中,站在立体内部看图片,比如说正方体中,画在内贴过程中比例会出现不协调,怎么可以处理一下使比例能和原来的一致,咋可以解决这个问题?如果立体图形改成别的?
 
不是吧。。。
 
锁定纵横比例尺,并与立体的比例保持不变。
 
看看这段代码


procedure TForm1.TiltBitmap(const InBitmap, OutBitmap: TBitmap;
const WidthTop, WidthBottom: integer);
const
clBackColor = clBlack;
BestQuality = True;
var
y, xWidthDiff, xWidthCurrentLine: Integer;
d: Real;
begin
OutBitmap.PixelFormat := InBitmap.PixelFormat;
if WidthTop > WidthBottom then
OutBitmap.Width := WidthTop
else
OutBitmap.Width := WidthBottom;
OutBitmap.Height := InBitmap.Height;
OutBitmap.Canvas.Brush.Color := clblack;
OutBitmap.Canvas.FillRect(OutBitmap.Canvas.ClipRect);
OutBitmap.Canvas.CopyMode := cmSrcCopy;
if BestQuality then
begin
{slower but better quality with color images}
SetStretchBltMode(OutBitmap.Canvas.Handle, HALFTONE);
SetBrushOrgEx(OutBitmap.Canvas.Handle, 0, 0, nil);
end
else
{quicker but slightly lower quality}
SetStretchBltMode(OutBitmap.Canvas.Handle, HALFTONE);
OutBitmap.Canvas.CopyMode := cmSrcCopy;
d := (WidthBottom - WidthTop) / OutBitmap.Height;

for y := 0 to OutBitmap.Height - 1 do
begin
xWidthCurrentLine := Trunc(WidthTop + d * y);
xWidthDiff := (OutBitmap.Width - xWidthCurrentLine) div 2;
OutBitmap.Canvas.CopyRect(Rect(xWidthDiff, y, xWidthDiff +
xWidthCurrentLine, y + 1),
InBitmap.Canvas, Rect(0, y, InBitmap.Width, y + 1));
end;
end;


var
InBitmap, outbitmap: Tbitmap;
begin
if Image1.Picture.Bitmap.Empty then
begin
ShowMessage('请加载图片');
exit;
end
else
InBitmap := TBitmap.Create;
outbitmap := TBitmap.Create;
InBitmap.Assign(image1.Picture.Bitmap);
TiltBitmap(InBitmap, OutBitmap, 300, 600);
image1.Picture.Bitmap.Assign(outbitmap);
image1.Invalidate;
InBitmap.Free;
outbitmap.Free;
end;

 
后退
顶部