zoukankan      html  css  js  c++  java
  • SkCanvas

    2011-11-10/15:41:16

    SkCanvas私有成员类

    private:
        class MCRec;
    

      

    /* This is the record we keep for each save/restore level in the stack.
    Since a level optionally copies the matrix and/or stack, we have pointers
    for these fields. If the value is copied for this level, the copy is
    stored in the ...Storage field, and the pointer points to that. If the
    value is not copied for this level, we ignore ...Storage, and just point
    at the corresponding value in the previous level in the stack.
    */

    这个类是在堆栈中保存每一个 save/restore level 的记录

    一个level 可选地复制 matrix 和/或 stack,我们有这些matrix / stack的指针。

    如果一个level 的matrix 或者stack 被拷贝,他的副本被保存在存储区域,并由指针指向他,

    如果没有被拷贝,我们就忽略他,指针指向栈中以前 level 的响应值

    2011-11-26/15:21:34  --- code.google.wiki翻译

    http://code.google.com/p/skia/wiki/SkCanvas

    SkCanvas 

    The drawing context 绘图上下文

    SkCanvas是Skia的绘图上下文,由它控制直接往哪里绘图(即缓冲屏幕的像素)。

    SkCanvas维持矩阵和裁剪区域的堆栈。但是不像其他API集(postscript,cairo,awt)的绘图上下文,Skia在绘图上下文不维持其他的绘图属性(例如颜色、画笔尺寸)。颜色、画笔尺寸这些属性在每次的绘画调用中通过SkPaint明确指定。

    canvas.save();
    canvas.rotate(SkIntToScalar(45));
    canvas.drawRect(rect, paint);
    canvas.restore();
    

      上门的代码绘画一个旋转45°的矩形。矩形的具体绘制颜色和风格由paint指定,而不是canvas。

    To setup a canvas to begin drawing is very straight-forward

    (straight-forward ? 简单?)

    所需要做的就是告诉canvas你想往哪里绘图(告诉canvas将要绘制的像素)。通常,像素通过位图指定,所以,创建canvas的时候指定一个bitmap就可以了。

    SkBitmap bitmap;
    bitmap.setConfig(SkBitmap::kARGB_8888_Config, 200, 100);
    bitmap.allocPixels();  // have the bitmap allocate memory for the pixels offscreen
    

     另外,如果已经分配内存或者想要画到特定的地方或者屏幕,需要明确给位图指定内存。

    bitmap.setConfig(SkBitmap::kARGB_8888_Config, 200, 100);
    bitmap.setPixels(address);
    

     setConfig()的第四个参数是可选的。第四个参数指定像素每行间的rowBytes,如果没有指定,默认参数是根据宽度和像素尺寸计算的,通常是4的倍数。

    到这里,就做好了绘图的准备。

    SkCanvas canvas(bitmap);
    

     如果想在创建canvas后指定位图,调用如下:

    canvas.setBitmapDevice(bitmap);
    

    开始绘制的时候,我们可能想要擦除整个画布。可以通过绘制一个很大的矩形来实现,更简单的方法是

    canvas.drawPaint(paint);
    

     以上调用用paint指定的颜色或者着色器(和xfermode)填充了整个画布(canvas),

    (though respecting the current clip of course 实际意思是仍会遵循当前的裁剪,也就是如果canvas当前有裁剪区域,drawPaint也只能绘制裁剪范围内)。

    如果paint选定了一个shader,也会respect canvas当前的矩阵。(canvas的当前矩阵设置仍会产生作用,平移、旋转、缩放等)

    如果你只是想绘制一种颜色(通过指定的xfermode),你可以只调用drawColor(),省去你自己创建paint对象,如下

    canvas.drawColor(SK_ColorWHITE);
    

     所有的绘图api都很相似,每个都以一个paint参数结束

    canvas.drawRect(rect, paint);
    canvas.drawOval(oval, paint);
    canvas.drawCircle(x, y, radius, paint);
    canvas.drawRoundRect(rect, rx, ry, paint);
    canvas.drawPath(path, paint);
    canvas.drawBitmap(bitmap, x, y, &paint);
    canvas.drawBitmapRect(bitmap, &srcRect, dstRect, &paint);
    canvas.drawBitmapMatrix(bitmap, matrix, &paint);
    canvas.drawText(text, length, x, y, paint);
    canvas.drawPosText(text, length, pos[], paint);
    canvas.drawTextOnPath(text, length, path, paint);
    

     一些api调用需要传递一个paint指针,而不是paint引用,这时候,paint参数可以为空。

     其他任何情况paint参数是必须的。

     

     ezhong的博客园:http://www.cnblogs.com/ezhong/

  • 相关阅读:
    Google基本利用
    sqlmap
    kali中wireshark打开后错误
    Python Flask Jinja2模板引擎
    Python Flask学习
    Python 豆瓣日记爬取
    Python 函数装饰器
    Python 生成器
    ss源码学习--从协议建立到完成一次代理请求
    ss源码学习--工作流程
  • 原文地址:https://www.cnblogs.com/ezhong/p/2244581.html
Copyright © 2011-2022 走看看