这仅与编程相关 - 与颜色及其表示还有更多工作要做。
我正在开发一个非常低级的应用程序。我在内存中有一个字节数组。那些是字符。它们使用抗锯齿渲染:它们的值从 0 到 255,0 表示完全透明,255 表示完全不透明(如果您愿意,可以使用 alpha)。
我在构思渲染这种字体的算法时遇到了麻烦。我正在为每个像素执行以下操作:
// intensity is the weight I talked about: 0 to 255
intensity = glyphs[text[i]][x + GLYPH_WIDTH*y];
if (intensity == 255)
continue; // Don't draw it, fully transparent
else if (intensity == 0)
setPixel(x + xi, y + yi, color, base); // Fully opaque, can draw original color
else { // Here's the tricky part
// Get the pixel in the destination for averaging purposes
pixel = getPixel(x + xi, y + yi, base);
// transfer is an int for calculations
transfer = (int) ((float)((float) (255.0 - (float) intensity/255.0) * (float) color.red + (float) pixel.red)/2); // This is my attempt at averaging
newPixel.red = (Byte) transfer;
transfer = (int) ((float)((float) (255.0 - (float) intensity/255.0) * (float) color.green + (float) pixel.green)/2);
newPixel.green = (Byte) transfer;
// transfer = (int) ((float) ((float) 255.0 - (float) intensity)/255.0 * (((float) color.blue) + (float) pixel.blue)/2);
transfer = (int) ((float)((float) (255.0 - (float) intensity/255.0) * (float) color.blue + (float) pixel.blue)/2);
newPixel.blue = (Byte) transfer;
// Set the newpixel in the desired mem. position
setPixel(x+xi, y+yi, newPixel, base);
}
如您所见,结果并不理想。这是一个非常放大的图像,在 1:1 的比例下,看起来文本有一个绿色的“光环”。
任何关于如何正确计算它的想法将不胜感激。
谢谢你的时间!