Reputation: 21
I have a draw(SkCanvas* canvas) function.
In main() I write:
SkBitmap myBitmap;
myBitmap.allocN32Pixels(640, 480);
SkCanvas *myCanvas(&myBitmap);
draw(myCanvas);
But Visual Studio generates this error:
"a value of type "SkBitmap *" cannot be used to initialize an entity of type "SkCanvas*"
What am I doing wrong?
My draw() function clutters the post and is completely useless for this question otherwise I've posted it.
This is the construction for SkCanvas.
/** Construct a canvas with the specified bitmap to draw into.
@param bitmap Specifies a bitmap for the canvas to draw into. Its
structure are copied to the canvas.
*/
explicit SkCanvas(const SkBitmap& bitmap);
Upvotes: 0
Views: 622
Reputation: 275800
SkCanvas *myCanvas(&myBitmap);
this is a pointer to a canvas. The pointer types of SkCanvas*
and SkBitmap*
are unrelated.
SkCanvas myCanvas(&myBitmap);
this is a value of type myCanvas
, initialized with a pointer to bitmap. If SkCanvas
has a ctor taking a SkBitmap*
, this should work.
It does not. It does have:
explicit SkCanvas(const SkBitmap& bitmap);
so this means:
SkCanvas myCanvas(myBitmap);
You'll probably also need to change the draw call to this:
draw(&myCanvas);
assuming that works. As a guess, you also need a refresher on the difference between pointers and values.
Upvotes: 1