Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/* 
 * Copyright (C) 2011 team-cachebox.de
 *
 * Licensed under the : GNU General Public License (GPL);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.gnu.org/licenses/gpl.html
 *
 * 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 android.graphics.Canvas;

import android.graphics.PorterDuff.Mode;
import android.graphics.Rect;

import android.graphics.drawable.Drawable;

public class Main {
    public static int PutImageTargetHeightColor(Canvas canvas, Drawable image, int x, int y, int height,
            int color) {
        return PutImageTargetHeightColor(canvas, image, x, y, height, color, Mode.MULTIPLY);
    }

    public static int PutImageTargetHeightColor(Canvas canvas, Drawable image, int x, int y, int height, int color,
            Mode porterDuff) {

        float scale = (float) height / (float) image.getIntrinsicHeight();
        int width = (int) Math.round(image.getIntrinsicWidth() * scale);

        Rect oldBounds = image.getBounds();
        image.setBounds(x, y, x + width, y + height);
        image.setColorFilter(color, porterDuff);
        image.draw(canvas);
        image.setBounds(oldBounds);
        image.clearColorFilter();
        return width;
    }
}