x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Getting random color pixels from Texture2D

I have been trying to get the RGB values of a specific pixel in my texture2D, unfortunately I keeps giving me different values for the same pixel which leads me to believe I did something wrong. I don't think my pixel rgb should change since it's the same texture every time, although every time I run my program I reimport the image, but I don't think that should have an effect because its the exact same image. I change the settings of my Texture2D before I start to find the pixel information but it still returns random colors

 FColor UMyFileImporter::GetPixelData(UTexture2D* Texture, int32 X, int32 Y)
     {
         Texture->MipGenSettings.operator=(TMGS_NoMipmaps);
         Texture->SRGB = false;
         Texture->CompressionSettings.operator=(TC_VectorDisplacementmap);
         FTexture2DMipMap* MyMipMap = &Texture->PlatformData->Mips[0];
         FByteBulkData* RawImageData = &MyMipMap->BulkData;
         FColor* FormatedImageData = static_cast<FColor*>(RawImageData->Lock(LOCK_READ_ONLY));
         uint8 PixelX = X, PixelY = Y;
         uint32 TextureWidth = MyMipMap->SizeX, TextureHeight = MyMipMap->SizeY;
         FColor PixelColor;
         if (PixelX >= 0 && PixelX < TextureWidth && PixelY >= 0 && PixelY < TextureHeight)
         {
             PixelColor = FormatedImageData[PixelY * TextureWidth + PixelX];
         }
         RawImageData->Unlock();
         return PixelColor;
     }
Product Version: UE 4.8
Tags:
more ▼

asked Jul 28 '15 at 03:14 PM in C++ Programming

avatar image

KikyoPorter
22 15 17 17

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

My method works. There was something wrong with the Texture I was getting.

more ▼

answered Jul 30 '15 at 08:03 PM

avatar image

KikyoPorter
22 15 17 17

avatar image Dovlahkin Jul 30 '16 at 01:06 PM

Hey, I did the same thing as you did, exactly the same, but my editor keeps crashing. Any idea why that might be happening? could you tell me how did you call this function, and what are your image import settings?

avatar image Hugh.Macdonald Jul 29 '18 at 10:16 PM

How did you get on with this?

I'm having a crash at the moment because FormattedImageData is coming up as a nullptr. I believe (still testing) that this is because the larger mipmaps hadn't been loaded. I'm now going through the mipmaps one at a time to find one where BulkData->BulkData is not nullptr and using that one.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question