2

I'm trying to convert the following PHP code to c# but I'm stuck with the imagecopy equivalent on c#. I used Graphics.DrawImage but seems didn't work.

PHP Code that works and generates smooth waved text

$xp = $this->scale*$this->Xperiod*rand(1,3);
$k = rand(0, 100);
for ($i = 0; $i < ($this->width*$this->scale); $i++) {
    imagecopy($this->im, $this->im,
    $i-1, sin($k+$i/$xp) * ($this->scale*$this->Xamplitude),
    $i, 0, 1, $this->height*$this->scale);
}

C# code I wrote using Graphics.ImageDraw that generates crappy result

variables before g.DrawImage are the ones php imagecopy uses.

int xp = scale * Xperiod * (new Random()).Next(1, 4);
int k = (new Random()).Next(1, 101);
for (int i = 0; i < (bitmap.Width * scale); i++)
{
    var dst_x = i - 1;
    var dst_y = Convert.ToInt32(Math.Sin(k + i / xp) * scale * Xamplitude);
    var src_x = i;
    var src_y = 0;
    var src_w = 1;
    var src_h = bitmap.Height * scale;
    g.DrawImage(bitmap, new Rectangle(dst_x, dst_y, 1, bitmap.Height), new Rectangle(src_x, src_y, src_w, src_h), System.Drawing.GraphicsUnit.Pixel);
}

Crappy result in C#

enter image description here

miken32
  • 42,008
  • 16
  • 111
  • 154
Ergec
  • 11,608
  • 7
  • 52
  • 62

0 Answers0