Android Open Source - HolographicSketch Bitmap Utils






From Project

Back to project page HolographicSketch.

License

The source code is released under:

GNU General Public License

If you think the Android project HolographicSketch listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright (C) 2011 HTC Corporation//  w  ww .  ja va 2  s.co m
 *
 * 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.
 */

package com.postgreen.stereo;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
import android.graphics.PorterDuffXfermode;
import android.graphics.Shader.TileMode;

// assorted bitmap utilities used with S3D image examples
public class BitmapUtils {

    public static Bitmap create2DBitmap(Bitmap bitmap) {

        int width = bitmap.getWidth();
        int height = bitmap.getHeight();

        float scaleWidth = 2f;
        float scaleHeight = 1f;

        Matrix matrix = new Matrix();
        matrix.postScale(scaleWidth, scaleHeight);

        // extract images by cropping and scaling with matrix
        Bitmap leftBitmap = Bitmap.createBitmap(bitmap, 0, 0, width / 2, height, matrix, true);
        // Bitmap rightBitmap = Bitmap.createBitmap(bitmap, width/2, 0, width/2,
        // height, matrix, true);

        // return left image as the 2D image
        return leftBitmap;
    }

    public static Bitmap createAnaglyphBitmap(Bitmap bitmap) {

        int width = bitmap.getWidth();
        int height = bitmap.getHeight();

        float scaleWidth = 2f;
        float scaleHeight = 1f;

        Matrix matrix = new Matrix();
        matrix.postScale(scaleWidth, scaleHeight);

        // extract images by cropping and scaling with matrix
        Bitmap leftBitmap = Bitmap.createBitmap(bitmap, 0, 0, width / 2, height, matrix, true);
        Bitmap rightBitmap = Bitmap.createBitmap(bitmap, width / 2, 0, width / 2, height, matrix,
                true);
        bitmap.recycle();

        // create result bitmap
        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inPreferredConfig = Config.ARGB_8888;
        Bitmap result = Bitmap.createBitmap(width, height, Config.ARGB_8888);
        result.eraseColor(Color.BLACK);

        // paint the left and right images onto canvas using red and cyan color
        // filters
        Paint red = new Paint();
        red.setShader(new BitmapShader(leftBitmap, TileMode.CLAMP, TileMode.CLAMP));
        red.setColorFilter(new PorterDuffColorFilter(Color.rgb(200, 0, 0), Mode.MULTIPLY));
        red.setXfermode(new PorterDuffXfermode(Mode.SCREEN));

        Paint cyan = new Paint();
        cyan.setShader(new BitmapShader(rightBitmap, TileMode.CLAMP, TileMode.CLAMP));
        cyan.setColorFilter(new PorterDuffColorFilter(Color.rgb(0, 200, 200), Mode.MULTIPLY));
        cyan.setXfermode(new PorterDuffXfermode(Mode.SCREEN));

        // use result bitmap for the canvas to draw into
        Canvas c = new Canvas(result);
        c.drawRect(0, 0, width, height, red);
        c.drawRect(0, 0, width, height, cyan);
        leftBitmap.recycle();
        rightBitmap.recycle();

        return result;
    }

}




Java Source Code List

com.postgreen.stereo.BitmapUtils.java
com.postgreen.stereo.ColorDialog.java
com.postgreen.stereo.ColorSwatchView.java
com.postgreen.stereo.ColorView.java
com.postgreen.stereo.EraseSketchDialog.java
com.postgreen.stereo.FlexPoly.java
com.postgreen.stereo.IColorDef.java
com.postgreen.stereo.IColorSet.java
com.postgreen.stereo.ILineWidthDef.java
com.postgreen.stereo.InvertibleTransformationMat.java
com.postgreen.stereo.LineDesc.java
com.postgreen.stereo.LineWidthDialog.java
com.postgreen.stereo.LineWidthView.java
com.postgreen.stereo.PersistenceModel.java
com.postgreen.stereo.S3DGLSurfaceView.java
com.postgreen.stereo.S3DListActivity.java
com.postgreen.stereo.S3DOpenGLActivity.java
com.postgreen.stereo.SimpleEula.java
com.postgreen.stereo.TransformationMat.java
meta.AltLowList_HighList.java
meta.AltLowList_StringRec.java
meta.Callback.java
meta.DataFormatException.java
meta.DecoderObjectInput.java
meta.EncoderObjectOutput.java
meta.FlexReader.java
meta.FlexString.java
meta.HighLevelBinTree.java
meta.HighLevelList.java
meta.LowLevelBinTree.java
meta.LowLevelList.java
meta.LowLevelType.java
meta.Meta.java
meta.PrimitiveThrowHandler.java
meta.Staque.java
meta.StdLowLevelBinTree.java
meta.StdLowLevelList.java
meta.StringRec.java
meta.VersionBufferNode.java
meta.VersionBuffer.java
meta.WrapRuntimeException.java