Skip to content

Commit c111175

Browse files
committed
Added getBase64 method
1 parent c65e3c7 commit c111175

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

src/textures/TextureManager.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,39 @@ var TextureManager = new Class({
255255
}
256256
},
257257

258+
getBase64: function (key, frame)
259+
{
260+
var data = '';
261+
262+
var textureFrame = this.getFrame(key, frame);
263+
264+
if (textureFrame)
265+
{
266+
var cd = textureFrame.canvasData;
267+
268+
var canvas = CanvasPool.create2D(this, cd.width, cd.height);
269+
var ctx = canvas.getContext('2d');
270+
271+
ctx.drawImage(
272+
textureFrame.source.image,
273+
cd.x,
274+
cd.y,
275+
cd.width,
276+
cd.height,
277+
0,
278+
0,
279+
cd.width,
280+
cd.height
281+
);
282+
283+
data = canvas.toDataURL('image/png').replace(/^data:image\/(png|jpg);base64,/, '');
284+
285+
CanvasPool.remove(canvas);
286+
}
287+
288+
return data;
289+
},
290+
258291
/**
259292
* Adds a new Texture to the Texture Manager created from the given Image element.
260293
*

0 commit comments

Comments
 (0)