Jump to content

Loading a texture directly from image?


2dt
 Share

Recommended Posts

The Texture class is created from a BaseTexture which is created from a texture source (such as an image or canvas). When you do "PIXI.Texture.fromImage('my/url/image.png');" basically what happens is this:

var img = new Image();img.src = 'my/url/image.png';var base = new PIXI.BaseTexture(img),    texture = new PIXI.Texture(base);// return you the texture

If you already have the image, you can just create a base texture from it and thereby a texture that you can use in your sprites. Hope this helps.

Link to comment
Share on other sites

  • 6 years later...
1 hour ago, MichalGo said:

Hello. Is there a way to do same with ImageBitmap? As I can see currently it is not possible to inject bitmap into BaseTexture as a resource.

Use "new BaseTexture(imageBitmap)" in latest pixi (5.1 or 5.2) . Or directly "new BaseTexture(new PIXI.resources.ImageBitmapResource(imageBitmap))"

Edited by ivan.popelyshev
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...