# Adding a texture

**URL:** <https://forum.babylonjs.com/t/adding-a-texture/3149>\
**Category:** Questions\
**Created:** [May 11, 2019, 6:15pm UTC](https://forum.babylonjs.com/t/adding-a-texture/3149 "2019-05-11T18:15:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JulesClair](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@JulesClair](https://forum.babylonjs.com/u/JulesClair)\
**Post date:** [May 11, 2019, 6:15pm UTC](https://forum.babylonjs.com/t/adding-a-texture/3149/1 "2019-05-11T18:15:15Z")

</div>

The dynamic texture does not apply to the model. Not sure what am I doing wring.

```
var engine = new BABYLON.Engine(canvas, true);
var scene = new BABYLON.Scene(engine);

function chnageTexture(){
  var mesh = scene.getMeshByName(m);  
  var texture = new BABYLON.DynamicTexture("dynamic texture", document.getElementById("canvas1"), scene);
  var textureContext = texture.getContext();
  var mat = new BABYLON.StandardMaterial("mat", scene);
  mat.diffuseTexture = texture;
  mesh.material = mat;
}

```

Is this because I’m using a canvas that is already existing? The examples in the documentation show how to draw a canvas and apply on the fly.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [May 13, 2019, 3:23pm UTC](https://forum.babylonjs.com/t/adding-a-texture/3149/2 "2019-05-13T15:23:56Z")

</div>

This **should** work 🙂  
Is there any error on the console? If your canvas contains tainted data you will not be able to use it

---

<div class="post-metadata">

**Author:** ![JulesClair](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@JulesClair](https://forum.babylonjs.com/u/JulesClair)\
**Post date:** [May 13, 2019, 6:17pm UTC](https://forum.babylonjs.com/t/adding-a-texture/3149/3 "2019-05-13T18:17:36Z")

</div>

Thank you @Deltakosh 🙂  
After googling for many hours I figured it out… it was an issue with the `.hasAlpha` . It’s all good now! I’m new to babylonjs and relay enthusiastic about what it can do. I’m trying to build an application with it… 🙂

I have a quick question. I’d very much appreciate if you could share your thoughts on this. IN my application I am thinking of allowing the user to generate textures at run time (canvas) and at the end to be able to send it via email. I am having doubts about whether to use base64 or Blob. While I was googling to find out about the performance of each one, I learned that using base64 has some performance issues on mobiles. So what I want to know in your opinion what would be the best way to handle the images (base64 for the textures and sending a image of the 3d to the server for emailing)?

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [May 14, 2019, 1:36am UTC](https://forum.babylonjs.com/t/adding-a-texture/3149/4 "2019-05-14T01:36:38Z")

</div>

Blob will let you store binary data directly but honestly unless you generate 100 images per frame base64 will perfectly do the job 🙂

---

<div class="post-metadata">

**Author:** ![JulesClair](https://avatars.discourse-cdn.com/v4/letter/j/71c47a/32.png) [@JulesClair](https://forum.babylonjs.com/u/JulesClair)\
**Post date:** [May 14, 2019, 4:36am UTC](https://forum.babylonjs.com/t/adding-a-texture/3149/5 "2019-05-14T04:36:19Z")

</div>

Thank you very much @Deltakosh 🙂 🙂
