繁体   English   中英

调整Tbitmap大小时的白色图像

[英]White image when resizing Tbitmap

该代码应该调整TBitmap大小,但生成的位图只是白色图像(具有最终大小)。 我正在使用它来调整为较小的尺寸。

function ResizeBitmap(B: TBitmap; Width, Height: Integer): TBitmap;
var
  finalbitmap: TBitmap;
begin
  finalbitmap := TBitmap.Create(Width, Height);
  finalbitmap.Clear(0);
  if finalbitmap.Canvas.BeginScene then
  try 
    finalbitmap.Canvas.DrawBitmap(B, RectF(0,0,B.Width,B.Height), RectF(0,0,Width,Height), 1);
  finally
    finalbitmap.Canvas.EndScene;
  end;
  Result := finalbitmap;
end;

知道发生了什么吗?

最后,我修改了php以调整上传图像的大小。 我不知道我的delphi代码出了什么问题。

<?php 
$uploaddir = strval($_GET['dir']); 
$newwidth = strval($_GET['newwidth']); 
$newheight = strval($_GET['newheight']); 
$uploadfile = $uploaddir . basename( $_FILES['file']['name']); 
move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile);
$sourceProperties = getimagesize($uploadfile);
$fileNewName = $_FILES['file']['name'];
$imageType = $sourceProperties[2];
$imageResourceId = imagecreatefrompng($uploadfile); 
$targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1],$newwidth,$newheight);
imagepng($targetLayer,$uploaddir. "thumb". $fileNewName);
move_uploaded_file($uploadfile, $uploaddir. $fileNewName. ".". "png");

function imageResize($imageResourceId,$width,$height,$twidth,$theigth) {
    $targetWidth =$twidth;
    $targetHeight =$theigth;
    $targetLayer=imagecreatetruecolor($twidth,$theigth);
    imagecopyresampled($targetLayer,$imageResourceId,0,0,0,0,$twidth,$theigth, $width,$height);
    return $targetLayer;
}
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM