Here you can find the source of unweaveFrom(BufferedImage bufferedImage)
Parameter | Description |
---|---|
bufferedImage | the buffered image |
public static String unweaveFrom(BufferedImage bufferedImage)
//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(); } }