该代码应该调整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;
知道发生了什么吗?
答案 0 :(得分:0)
最后,我修改了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;
}
?>