Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Convert a Bitmap to Gray Scale Android example


AD MOB

Black and white bitmap image pictures, gray scale colormatrix Android example.

public class ApokusActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}

		@Override
		protected void onDraw(Canvas canvas) {
			Paint paint = new Paint();

			canvas.drawColor(Color.YELLOW);


			// you need to insert a image flower_blue into res/drawable folder

			paint.setFilterBitmap(true);
			Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
					R.drawable.flower_blue);
			canvas.drawBitmap(bitmapOrg, 10, 10, paint);
			int width, height;

		    ColorMatrix cm = new ColorMatrix(
		    		new float[]{
		    		0.5f,0.5f,0.5f,0,0,
		            0.5f,0.5f,0.5f,0,0,
		            0.5f,0.5f,0.5f,0,0,
		            0,0,0,1,0,0,
		            0,0,0,0,1,0
		            });
		    cm.setSaturation(0);
		    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
		    paint.setColorFilter(f);
		    int h = bitmapOrg.getHeight();
			//canvas.drawBitmap(bitmapOrg, 10, 10, paint);
			canvas.drawBitmap(bitmapOrg, 10, 10 + h + 10, paint);

		}

	}
}




gry scale bitmap android

397LW NO topic_id




AD

Další témata ....(Topics)


210

No Launcher activity found Android Emulator Error | no-launcher-activity-found-android-emulator-error


Error: No Launcher activity found!
The launch will only sync the application package on the device!
Android emulator not showing the app
Workaround:
Check AndroidManifest.xml for MAIN and LAUNCHER. MyActivity.java is first Activity what will opened if .apk is installed.

<application android:label="@string/app_name" android:icon="@drawable/icon">
    <activity android:name="MyActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
5

Random number Java | random-number-java


Generate random number Android Java example source code.

		Random rand = new Random();
		int i = rand.nextInt() % 256; // range -255  +255
		System.out.print(i + "

"); // -184 i = Math.abs(rand.nextInt() % 12); // range 0 +11 System.out.print(i); // 7



// Math.random() start with 0.  e.g. 0.35981234 
int nRan = (int) (Math.random()*10); // 0 - 10

// nextDouble(), nextFloat(), nextInt(), nextLong() returns 0 - 10
import java.util.Random;´

Random r = new Random();
int nRan = r.nextInt(); // 0 - 10
double dRan = r.nextDouble() * 10; // e.g. 7.496285271597397

nextDouble – return 0 - 1
nextFloat – same as double
nextInt –  -2147483648  +2147483647
nextLong –  -922337203685775808  +9223372036854775807
nextGaussian –  0.0 aberation 1.0.
190

Get Screen Size Pixels per Inch Android example | get-screen-pixels-android-example


The exact physical pixels per inch of the screen
Get size of pixel
Get DPI
Get count of pixels per inch

        float mXDpi;
        float mYDpi;
           DisplayMetrics metrics = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(metrics);
            mXDpi = metrics.xdpi; // The exact physical pixels per inch of the screen in the X dimension. 
            mYDpi = metrics.ydpi;
          float  mMetersToPixelsX = mXDpi / 0.0254f; // 1 inch == 0.0254 metre
          float  mMetersToPixelsY = mYDpi / 0.0254f;


287

AlertDialog setButton Deprecated | alertdialog-setbutton-deprecated


Solution:

public void alertMy(String sTitle, String sMessage){
	AlertDialog.Builder builder = new AlertDialog.Builder(Test.this); // activity
  builder.setTitle(sTitle)
  .setMessage(sMessage)
  .setCancelable(false)
  .setNegativeButton("Close",new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int id) {
          dialog.cancel();
      }
  });
  AlertDialog alert = builder.create();
  alert.show();

}

94

Is NaN isNaN isInfinite number value Java Android example | is-nan-isnan-java-example


float, double is NaN isNaN() isInfinite() Java Android example.

float f = 0.f;
boolean bIsNaN = Float.isNaN(f);
boolean bIsInfinite = Float.isInfinite(f);

 double d = Math.sqrt(-10);
 boolean b = Double.isNaN(d);



Editace: 2013-12-09 13:09:13
Počet článků v kategorii: 397
Url:convert-a-bitmap-to-gray-scale-android-example

AD
11 Share
Share
Tweet