Bazi
Bazi

Reputation: 37

White image when resizing Tbitmap

This code is supposed to resize a TBitmap, but the resulting bitmap is just a white image (with the final size). I'm using it to resize to a lower size.

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;

Any idea what is happening?

Upvotes: 0

Views: 251

Answers (1)

Bazi
Bazi

Reputation: 37

Finally I've modified the php to resize the uploaded image. I'm not able to know what is wrong with my delphi code.

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

Upvotes: 0

Related Questions