Method: RGD::Image#copy
- Defined in:
- ext/rgd/rgd.c
#copy(src, dstX, dstY, srcX, srcY, w, h) ⇒ Object
Used to copy a rectangular portion of one image to another image. (For a way of stretching or shrinking the image in the process, see Image.copy_resized.)
The dst argument is the destination image to which the region will be copied. The src argument is the source image from which the region is copied. The dstX and dstY arguments specify the point in the destination image to which the region will be copied. The srcX and srcY arguments specify the upper left corner of the region in the source image. The w and h arguments specify the width and height of the region.
When you copy a region from one location in an image to another location in the same image, this method will perform as expected unless the regions overlap, in which case the result is unpredictable.
Important note on copying between images: since different images do not necessarily have the same color tables, pixels are not simply set to the same color index values to copy them. This method will attempt to find an identical RGB value in the destination image for each pixel in the copied portion of the source image by invoking Image.color_exact. If such a value is not found, this method will attempt to allocate colors as needed using Image.color_allocate. If both of these methods fail, this method will invoke Image.color_closest to find the color in the destination image which most closely approximates the color of the pixel being copied.
1508 1509 1510 1511 1512 1513 1514 |
# File 'ext/rgd/rgd.c', line 1508 static VALUE image_copy(VALUE klass, VALUE srcImg, VALUE dstX, VALUE dstY, VALUE srcX, VALUE srcY, VALUE w, VALUE h) { gdImagePtr dst, src; Data_Get_Struct(klass, gdImage, dst); Data_Get_Struct(srcImg, gdImage, src); gdImageCopy(dst, src, NUM2INT(dstX), NUM2INT(dstY), NUM2INT(srcX), NUM2INT(srcY), NUM2INT(w), NUM2INT(h)); return klass; } |