create Image : Image « 2D Graphics « Android






create Image

   
//package com.anoshenko.android.mahjongg;

import java.util.Random;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.preference.PreferenceManager;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

class Utils {

  public final static int DIE_COUNT = 36;

  private final static int DIE_FILL_COLOR    = 0xFFE0E0E0;
  private final static int DIE_BORDER_COLOR  = 0xFF808080;
  private final static int DIE_SIDE_COLOR    = 0xFFB0B0B0;
  private final static int DIE_ANGLE_COLOR  = 0xFFC0C0C0;

  //--------------------------------------------------------------------------
  static public Bitmap createDieImage(int width, int height, int wall_size) {
    Bitmap bitmap = Bitmap.createBitmap(width + wall_size, height + wall_size, Bitmap.Config.ARGB_8888);
    Canvas g = new Canvas(bitmap);
    Paint paint = new Paint();
    int right = width + wall_size - 1;
    int bottom = height + wall_size - 1;

    paint.setAntiAlias(false);
    paint.setStrokeWidth(1);

    g.drawARGB(0, 0, 0, 0);

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(DIE_FILL_COLOR);
    g.drawRect(wall_size, 1, right, height, paint);

    paint.setStyle(Paint.Style.STROKE);
    paint.setColor(DIE_ANGLE_COLOR);

    g.drawLine(wall_size-1, 1, wall_size-1, height, paint);
    g.drawLine(wall_size-1, height, right-1, height, paint);
    g.drawPoint(wall_size, 1, paint);
    g.drawPoint(wall_size, height-1, paint);
    g.drawPoint(right-1, 1, paint);
    g.drawPoint(right-1, height-1, paint);

    paint.setColor(DIE_SIDE_COLOR);

    for (int n=1; n<wall_size-1; n++) {
      g.drawLine(n, wall_size-n, n, bottom, paint);
      g.drawLine(1, bottom-n, right-wall_size+n, bottom-n, paint);
    }

    paint.setColor(DIE_BORDER_COLOR);

    g.drawLine(0, wall_size, 0, bottom, paint);
    g.drawLine(1, bottom, width, bottom, paint);

    g.drawLine(0, wall_size+1, wall_size+1, 0, paint);
    g.drawLine(width, bottom, right, height, paint);
    g.drawLine(1, bottom, wall_size, height, paint);
    g.drawLine(wall_size, 0, right, 0, paint);
    g.drawLine(right, 1, right, height, paint);

    return bitmap;
  }
}

   
    
    
  








Related examples in the same category

1.Capture Image
2.extends BaseAdapter to create Image adapter
3.extends BaseAdapter to create adapter for images
4.Capture Image and display
5.Load up the image's dimensions
6.Lazy Loading Image
7.Resize Image
8.Fit Image No Margin
9.To Rotate Texture Image
10.Image Resize
11.Create Image and resize Image
12.image To Byte
13.Image Loader
14.Save Image and Text to SD card
15.Scale and rotate Image
16.Resize Photo