getChannelSafe method

  1. @override
int getChannelSafe(
  1. int x,
  2. int y, [
  3. int? defaultValue,
  4. ImageChannel? channel,
])
override

get the gray value(0-255) at Point(x, y) without exception. channel is ignored

Implementation

@override
int getChannelSafe(int x, int y, [int? defaultValue, ImageChannel? channel]) {
  if (x >= 0 && x < width && y >= 0 && y < height) {
    return getChannel(x, y, channel);
  } else if (defaultValue == null) {
    if (x < 0) x = 0;
    if (x > width - 1) x = width - 1;
    if (y < 0) y = 0;
    if (y > height - 1) y = height - 1;
    return getChannel(x, y, channel);
  }
  return defaultValue;
}