Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I've tried looking everywhere online with no luck, so I've come here. Since nothing I've tried works, I'm think that Minecraft .png images have an unusual way of reading transparency? I'm trying to find the average color in a texture (ignoring transparent pixels). It works for the most part, except it also ignores black/white pixels (pixels with the same rgb values, example r=222, g=222, b=222). The code I am using is in the spoiler. Any help would be appreciated!

Spoiler

//textureName is the file location of the texture (in the form of a String), which works fine.

try {
                        BufferedImage image = ImageIO.read(Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation(textureName)).getInputStream());
                        int width = image.getWidth();
                        int height = image.getHeight();
                        float pixels = 0;
                        float r = 0;
                        float g = 0;
                        float b = 0;
                        for (int x = 0; x < width; x++) {
                            for (int y = 0; y < height; y++) {
                                Color color = new Color(image.getRGB(x, y));
                                if(color.getRGB() != -1) {
                                    pixels++;
                                    r += color.getRed();
                                    g += color.getGreen();
                                    b += color.getBlue();                       
                                }
                            }
                        }
                        if(pixels == width * height) {
                            float avgR = r / (pixels * 255.0F);
                            float avgG = g / (pixels * 255.0F);
                            float avgB = b / (pixels * 255.0F);
                            GlStateManager.color(avgR, avgG, avgB, 1.0F);
                            image.getGraphics().dispose();
                        }
                    } 
                    catch (IOException e) {
                        //e.printStackTrace();
                    }

 

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.