调整 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 以调整上传图像的大小。我无法知道我的德尔菲代码出了什么问题。

<?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;
}
?>

相关内容

  • 没有找到相关文章

最新更新