Java BufferedImage Operation unweaveFrom(BufferedImage bufferedImage)

Here you can find the source of unweaveFrom(BufferedImage bufferedImage)

Description

Unweave a secret message from the given BufferedImage .

License

Apache License

Parameter

Parameter Description
bufferedImage the buffered image

Return

the secret message

Declaration

public static String unweaveFrom(BufferedImage bufferedImage) 

Method Source Code

//package com.java2s;
/**//  w w  w .  j a  v a 2 s  .  co m
 * Copyright (C) 2007 Asterios Raptis
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.awt.image.BufferedImage;

public class Main {
    /**
     * Unweave a secret message from the given {@link BufferedImage}.
     *
     * @param bufferedImage
     *            the buffered image
     * @return the secret message
     */
    public static String unweaveFrom(BufferedImage bufferedImage) {
        int width = bufferedImage.getWidth();
        int height = bufferedImage.getHeight();
        int messageLength = bufferedImage.getRGB(0, 0) & 0xff;
        StringBuilder sb = new StringBuilder();
        for (int row = 0, j = 0, i = 1; row < height; row++) {
            for (int column = 0; column < width && j < messageLength; column++, i++) {

                if (i % 11 == 0) {
                    int result = bufferedImage.getRGB(column, row);

                    int charAtPosition = (result >> 16 & 0x7) << 5;

                    charAtPosition |= (result >> 8 & 0x7) << 2;

                    charAtPosition |= result & 0x3;
                    sb.append((char) charAtPosition);
                    j++;
                }
            }
        }
        return sb.toString();
    }
}

Related

  1. thresholdImage(BufferedImage image, int threshold)
  2. tile(BufferedImage source, Rectangle r, GraphicsConfiguration conf)
  3. tileStretchPaint(Graphics g, Component component, BufferedImage image, Insets insets)
  4. tilt(BufferedImage image, double angle)
  5. tintImage(BufferedImage src, Color color, float tintOpacity)
  6. updateImageSpecifications( BufferedImage bufferedImage)
  7. validateSelectionRectangle(BufferedImage image, Rectangle selection)
  8. verticalGradient(BufferedImage image, Graphics2D g2d, Color... colors)
  9. waterMarkImage(final BufferedImage image, final String text)