Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Bitmap.Config;

public class Main {
    public static Bitmap RGB16ToBitmap(int width, int height, short[] data) {
        int ilength = data.length;
        int[] colors = new int[ilength];
        for (int i = 0; i < ilength; i++) {
            colors[i] = rgb565to24(data[i]);
        }
        Bitmap bmp = Bitmap.createBitmap(width, height, Config.ARGB_8888);

        return bmp;

    }

    public static int rgb565to24(short v) {
        int i = uShortToInt(v);
        byte r = (byte) (i & 0xF800 >> 11);
        byte g = (byte) (i & 0x07E0 >> 5);
        byte b = (byte) (i & 0x001F);
        return Color.rgb(r, g, b);

    }

    public static int uShortToInt(short ushort) {
        int v = ushort;
        if (v < 0) {
            v = v + 65536;
        }
        return v;
    }
}