Chinaunix首页 | 论坛 | 博客
  • 博客访问: 64112
  • 博文数量: 29
  • 博客积分: 1250
  • 博客等级: 中尉
  • 技术积分: 292
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-30 13:04
文章分类

全部博文(29)

文章存档

2009年(24)

2008年(5)

我的朋友

分类:

2009-03-23 14:54:13

 

Skia uses a custom type, SkScalar, for most of its routines to represent coordinates. Depending on the value of a compiler flag, this is either typedefed to a float for floating-point mode, or an int for fixed-point mode. In fixed-point mode, the high 16-bits represent the whole part of the number, and the low 16-bits represent the fractional part. Although we currently compile with floating-point mode, we want to leave open the option to move to fixed point mode. You should therefore be very careful and not pass integer or floating point values directly to these functions.

The easiest way is to use the *Int functions provided in ChromeCanvas if you are using one of the commonly-used functions that have wrappers. If this is not an option, you must use either SkIntToScalar or SkFloatToScalar to convert your value (an int or float, respectively), to the appropriate SkScalar type. To convert from scalars back to ints, use SkScalarRound.

Skia使用自定义类型的SkScalar来表示坐标系统。有两种表示方法:

浮点模式:定义SkScalarfloat

整数模式:定义SkScalarint,但高16为表示整数部分,低16位表示小数部分。

可以使用SkIntToScalar SkFloatToScalar来转换intfloatSkScalar值。SkScalarRound会值保留整数部分。

 

Skia 使用32位的RGBA表示颜色。

 

It is important to know that Skia uses premultiplied colors. This means that the color components have already been multiplied by the alpha channel. Most people are accustomed to having a color and then thinking about a separate opacity value. Premultiplied colors have already been "composited on black," allowing layers to be composited by addition of the color values rather than requiring an additional multiplication by alpha. Therefore, if the alpha is 50%, no color channels can have values greater than 50%.

Use SkPreMultiplyColor to convert from an SkColor to a premultiplied color value (SkPMColor).

Skia使用premultiplied颜色。比如,50%的白色就表示成FF*50%=7F.

可以使用SkPreMultiplyColor来转换SkColorpremultiplied color 值。

 

The model is that you use an SkCanvas to draw into an SkBitmap with an SkPaint. The SkBitmap (wrapped by an SkDevice) holds the bits, the SkCanvas manages the device and contains the drawing primitives, and the SkPaint holds most of the graphics state such as colors and antialiasing options. Most other graphics libraries combine the graphics state inside the canvas. SkPaint is lightweight and you should not generally worry about creating and destroying them as needed.

 

To draw a round rect:

// Create the canvas. Note that this is a SkCanvas and not a PlatformCanvas so

// we won't be able to draw text on it. The canvas first requires a backing store

// (SkPlatformCanvas doesn't need this since it creates its own backing store).

SkBitmap backing_store;

backing_store.setConfig(SkBitmap::kARGB_8888_Config, canvas_width, canvas_height);

backing_store.setIsOpaque(true); // This will make some things faster if it's opaque.

backing_store.allocPixels(); // Don't forget to call this or it will be invalid!

 

SkCanvas canvas(backing_store);

canvas.drawARGB(255, 255, 255, 255); // Fill with white.

 

// Make a rect from (0,0) to (100,75).

SkRect rect;

rect.set(SkIntToScalar(0), SkIntToScalar(0),

SkIntToScalar(100), SkIntToScalar(75));

 

// Create a path with that rect and rounded corners of radius 10.

SkPath path;

path.addRoundRect(rect, SkIntToScalar(10), SkIntToScalar(10));

 

// Fill the path (with antialiasing) in 50% transparent green.

SkPaint paint;

paint.setStyle(SkPaint::kFill_Style);

paint.setFlags(SkPaint::kAntiAlias_Flag);

paint.setARGB(128, 0, 255, 0);

canvas->drawPath(path, paint);

 

阅读(559) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~