imagesetpixel
Prev | Orchestra Opcodes and Operators | Next

## imagesetpixel

imagesetpixel — Set the RGB value of a pixel inside a previously opened or created image.

## Description

Set the RGB value of a pixel inside a previously opened or created image. An image can be loaded with imageload. An empty image can be created with imagecreate and saved with imagesave.

## Syntax

    imagesetpixel iimagenum, ax, ay, ared, agreen, ablue

    imagesetpixel iimagenum, kx, ky, kred, kgreen, kblue

## Initialization

iimagenum -- the reference of the image.. It should be a value returned by imageload or imagecreate.

## Performance

ax (kx) -- horizontal pixel position (must be a float from 0 to 1).

ay (ky) -- vertical pixel position (must be a float from 0 to 1).

ared (kred) -- red value of the pixel (mapped to a float from 0 to 1).

agreen (kgreen) -- green value of the pixel (mapped to a float from 0 to 1).

ablue (kblue) -- blue value of the pixel (mapped to a float from 0 to 1).

## Examples

Here is an example of the imagesetpixel opcode. It uses the file imageopcodes.csd.

Example 354. Example of the imagesetpixel opcode.

    <CsoundSynthesizer>
    <CsOptions>
    ; Select audio/midi flags here according to platform
    -n ;no sound output
    </CsOptions>
    <CsInstruments>

    sr=48000
    ksmps=1
    nchnls=2

    ; this test .csd copies image.png into a new file 'imageout.png'

    giimage1 imageload "image.png"
    giimagew, giimageh imagesize giimage1
    giimage2 imagecreate giimagew,giimageh

        instr 1

    kndx = 0
    kx_ linseg 0, p3, 1
    ;print imagewidth and imageheigth of image.png
    prints "imagewidth = %f pixels, imageheigth = %f pixels\\n", giimagew, giimageh

    myloop:
    ky_ = kndx/(giimageh)
    kr_, kg_, kb_ imagegetpixel giimage1, kx_, ky_
    imagesetpixel giimage2, kx_, ky_, kr_, kg_, kb_
    loop_lt kndx, 0.5, giimageh, myloop
        endin

        instr 2

    imagesave giimage2, "imageout.png"
        endin

        instr 3
    imagefree giimage1
    imagefree giimage2
        endin

    </CsInstruments>
    <CsScore>

    i1 1 1
    i2 2 1
    i3 3 1
    e

    </CsScore>
    </CsoundSynthesizer>

## See Also

imageload, imagecreate, imagesize, imagesave, imagegetpixel, imagefree

## Credits

Author: Cesare Marilungo

New in version 5.08

Prev | Up | Next
imagesave | Home | imagesize