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.

Crop cropped cut bitmap image pictures Android example

Cut, shear, clip, snip, crop a bitmap, picture, image Android example

public class ApokusActivity extends Activity {

	protected void onCreate(Bundle savedInstanceState) {
		setContentView(new SampleView(this));

	private static class SampleView extends View {

		public SampleView(Context context) {


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


			// you need to insert a image flower_blue into res/drawable folder
			Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),

			Bitmap croppedBmp = Bitmap.createBitmap(bitmapOrg, 0, 0,
					bitmapOrg.getWidth() / 2, bitmapOrg.getHeight());
			int h = bitmapOrg.getHeight();
			canvas.drawBitmap(bitmapOrg, 10, 10, paint);
			canvas.drawBitmap(croppedBmp, 10, 10 + h + 10, paint);



crop bitmap android

397LW NO topic_id

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


int java android example | int-java-android-example

int occupy 4 bytes (32 bits) in memory

int in Java example of using Integer and Array of Integer and Iteger to String

        // get max end min values of int in Java example 4 bytes (32 bits) PC architecture
	System.out.println(Integer.MAX_VALUE); // 2147483647
	System.out.println(Integer.MIN_VALUE); // -2147483648

// members variable
private int mProgress = 10;

//integer to string java
int myInteger = 8;
String myString = Integer.toString(myInteger);

// a final variable can only be initialized once
static final int NUM_PARTICLES = 15;

 for (int i = 0; i < NUM_PARTICLES ; i++) { 
// do something

// int as return value of function
public int getCount() {
return 5;

// int as a parametr of function
public float getFloatFromInt(int i) {
float fRet = (float) i;
 return fRet;

//array of int
int[] anArray;              // declares an array of integers
          anArray = new int[2];      // allocates memory for 2 integers
          anArray[0] = 100; // initialize first element
          anArray[1] = 200; // initialize second element

for (int i = 0; i < anArray.length; i++) {
// print out values from anArray
System.out.println("Index: " + i);
System.out.println("Value: " + anArray[i]); 


Android Studio failed to convert drawable into a drawable | android-studio-failed-to-convert-drawable-into-a-drawable

Try this:
- check names of drawables (file name must contain only abc...xyz 012...789 _ . in Resources folder ,
names have to start with lower case
MyImage.jpg == problem ,
names with space
my image.jpg == problem,
names with -
my-image.png == problem)
- check duplicate names with other extension ( my_image.jpg - my_image.png makes the problem)
- restart Android Studio
- if problem persist:
- check c:\Users\me\AndroidStudioProjects\myProject\myModule\build\intermediates\res\merged\debug\ drawable folder for corupted names or delete ALL drawable folders
- synk projekt, rebuild projekt
- if problem persist:
- restart Android Studio, wait for complete closure of the Android Studio!

Save Instance State if device is rotated | save-instance-state-if-device-is-rotated

Try this trick.
In AndroidManifest - activity tag write this code
App hold data of a views if will to rotation of device.

 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

How add Android code templates to Eclipse | how-add-android-code-templates-to-eclipse

If you have to type frequently the same code you can create templates which can be activate via autocomplete with Ctrl + Space.

For example lets assume setOnClickListener body.

To create a template for this select the menu Window->Preferences and Open Java -> Editor -> Templates

Create new Android template in Eclipse

Type name of template in Eclipse s editor and pres Ctrl+Space

[caption id="attachment_1114" align="alignleft" width="300" caption="Eclipse-show-template-proposals"]eclipse-show-template-proposals[/caption]

Select your template from intellisense help and press Enter or double click on selected item.

[caption id="attachment_1116" align="alignleft" width="300" caption="Eclipse - select your template"][/caption]

	mIdButtonHome.setOnClickListener(new View.OnClickListener() {
		public void onClick(View v) {
			Intent browserIntent = new Intent(Intent.ACTION_VIEW,

Quick help in Eclipse editor: select keyword and press Ctrl+1

Eclipse quick help

Start Activity from ListView item click Android example | start-activity-from-listview-item-click-android-example

How start certain Activity if user clicked to ListView item
Start Activity from list – launches other activities from list - latest variant!!!!

public class Main extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        try {
			ListView mlistView = (ListView) findViewById(R.id.idListView);
			mlistView.setAdapter(new ArrayAdapter<String>(this,
			        new String[] {"Game", "Help", "Home site"}));
        mlistView.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
              // When clicked, show a toast with the TextView text Game, Help, Home
              Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
              String sText = ((TextView) view).getText().toString();
              Intent intent = null;
              intent = new Intent(getBaseContext(),
              //else if(sText.equals("Help")) ..........

              if(intent != null)
        } catch (Exception e) {
        	// TODO Auto-generated catch block

Game class Game.java game.xml
You have to add class Game to AndroidManifest.xml

        <activity android:name=".Game" android:label="GameLabel">

package cz.okhelp.listview;

import android.app.Activity;
import android.os.Bundle;

public class Game extends Activity{
    public void onCreate(Bundle savedInstanceState) {
        // you have to create game.xml 

Editace: 2011-11-14 10:57:34
Počet článků v kategorii: 397