Announcement

Collapse
No announcement yet.

Draw RGB Values

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Draw RGB Values

    Hi, I have the following Problem: I get sent by a Sever RGBA values from a picture that was calculated on a server, currently the picture is 300x300 pixels, so I have 360000 Values, 4 for every Pixel. How can I display this image based on the RGBA values in the Unreal Engine? I tried to draw the image pixel for pixel on a Canvas but this crashes because there are too many points to draw. Does anyone have another idea how i can make this better?

    #2
    Just create a texture instead and use that.

    Comment


      #3
      Typically when you're working with texture data at runtime you only have one option that's worth doing:

      1. Check that your byte data and channel order are exactly the same - e.g. RGBA8, not BGR16 or RG32 or something equally wrong.
      2. memcpy() your data from its location in memory to an empty texture in a single operation. It might help to use a Canvas2D still as it reveals some useful methods in general.

      This is faster and much less work. If you end up needing to swizzle or convert the pixel data the time it takes to process it is going to increase by a factor of over a hundred. If your pixel data is just something like string values from a request and not binary that you can stick into memory then you're definitely stuck doing a slow conversion.

      UE does manage your memory for you but with operations like this - even in blueprints - you're going to have to be aware of how memory management works and put it together smartly. I'd almost certainly say to use C++ to do this so you have implicit control over what gets created and released as it runs.

      If you find your texture data is binary but in some other format, there's still one more option: fix it in the shader. If you have a matching UE texture format available to you, use that. If not just write it as RGB(whatever the byte value is) and swap the channels in the shader.

      If nothing has changed since I did it the this process is pretty low level and it requires good knowledge of C++ and the engine, but if you dig through UTexture2D and UTexture's source you'll find all of the methods and places to stick data that you need. Don't forget that once you push all of the data into the texture object you'll want to stop it from ever garbage collecting until you definitely don't need it again, otherwise you'll have to start the whole process over. Also I don't think there's any way to package and save the texture at runtime, you'd need to save it somehow and load it in each and every time if you wanted to store it locally.
      Last edited by Antidamage; 10-14-2019, 04:08 PM.

      Comment

      Working...
      X