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 Drawable to Bitmap to Drawable




Context context = getApplicationContext();
Drawable drawable = context.getResources().getDrawable(R.drawable.my_image);
// convert drawable to bitmap
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();
// convert bitmap to drawable
Drawable d = new BitmapDrawable(bitmap);

Android example source code.

397LW NO topic_id



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


153

Rotate Canvas with Bitmap Android example | rotate-canvas-with-bitmap-android-example


drawPath, canvas.rotate, lineTo basic Android example for your testing.





canvas-rotate-image-android-1


canvas-rotate-image-android




// //www.apache.org/licenses/LICENSE-2.0
// The Android Open Source Project
public class MainActivity extends Activity {

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

	private static class SampleView extends View {
		private Paint mPaint = new Paint();
		private Path mPath = new Path();

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

			// Construct a wedge-shaped path
			mPath.moveTo(0, -60);
			mPath.lineTo(-20, 80);
			mPath.lineTo(0, 60);
			mPath.lineTo(20, 80);
			mPath.close();
		}

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

			canvas.drawColor(Color.WHITE);

			paint.setAntiAlias(true);
			paint.setColor(Color.RED);
			paint.setStyle(Paint.Style.FILL);
			Bitmap bitmapOrg = BitmapFactory.decodeResource(getResources(),
					R.drawable.flower_blue);
			canvas.drawBitmap(bitmapOrg, 10, 10, paint);
			int w = canvas.getWidth();
			int h = canvas.getHeight();
			int cx = w / 2;
			int cy = h / 2;

			canvas.translate(cx, cy);
         // uncomment next line 
			//canvas.rotate(90.0f);
			canvas.drawPath(mPath, mPaint);
		}

	}
}
359

Saving Activity state int String Array Double on Android | saving-activity-state-int-string-array-double-on-android



private int[] mData = new int[2]; // fill some values into array!!
 @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putBoolean("myBoolean", true);
        outState.putDouble("myDouble", 2.7);
        outState.putInt("myInt", 5);
        outState.putString("myString", "Heloo girls!");
       int[] data = new int[mData.length];
        for (int i = 0; i < data.length; i++) {
            data[i] = mData[i];
        }
        outState.putIntArray("myArray", data);

    }
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
  super.onRestoreInstanceState(savedInstanceState);
  boolean myBoolean = savedInstanceState.getBoolean("myBoolean", false); // false basic value
  double myDouble = savedInstanceState.getDouble("myDouble", 1.5); // 1.5 basic value
  int myInt = savedInstanceState.getInt("myInt", 10);
  String myString = savedInstanceState.getString("myString", "Hello boys!");
  int[] data = savedInstanceState.getIntArray("myArray");
  
  if (data != null && data.length == mData.length) {
            for (int i = 0; i < data.length; i++) {
                mData[i] = data[i];
            }
        }
}
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  boolean myBoolean =  savedInstanceState != null ? savedInstanceState.getBoolean("myBoolean", false) : true;
// etc.  .......
}

366

Center View in RelativeLayout Android | center-view-in-relativelayout-android


RelativeLayout like parent, child Srollview is centered horizontal.
Second RelativeLayout in SrollView have gravity center, every child will centered horizontally and vertically.


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="//schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:gravity="center_horizontal">

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/scrollView2" >

        <RelativeLayout
            android:layout_width="320dp"
            android:layout_height="wrap_content"
            android:background="#e6f825"
            android:gravity="center">

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New Button"
                android:id="@+id/button" />
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>
178

HTC Desire HD | htc-desire-hd


HTC Desire HD cena od 7 000 KCZ Kč (únor.2012)
HTC Desire HD je chytrý telefon běžící na operačním systému Android.
HTC Desire HD je (22.února2012) druhým nejpoužívanějším chytrým telefonem u programu Sky Map viz tabulka.

Smartphone má hliníkový unibody design, vybaven je Androidem 2.2 (Froyo) a HTC Sense displayem. Na zadní straně jsou dvě plastové krytky, jedna obsahuje baterii, druhá SIM kartu a paměťovou kartu microSDHC. Telefon je vybaven 4,3 palcovým WVGA LCD TFT dotykovým displayem, 8 megapixelovým fotoaparátem (lze nahrávat 720p video), podpora pro HSPA / W-CDMA a quad-band GSM / GPRS / EDGE.


Telefon je vybaven 1 GHz CPU Scorpion MSM8255 procesorem. Tato druhá generace Snapdragon procesoru má nízkou spotřebu energie.

HTC HD má 768 MB RAM a 1,5 GB interní paměti flash. K dispozici je také slot pro microSDHC / XC kartu s kapacitou až 32 GB dat.

HTC Desire HD photo pic image
samsung galaxy s2
Zdroj obrázku: wikipedia
349

Android Google Maps Night Mode | android-google-maps-night-mode


If you want save battery, select "Satelite map" from map menu and reduce the brightness of the display.

android-google-maps-night-mode-as-satelite-map.jpg


Editace Jana Žákovská : 2013-12-09 13:08:29
Počet článků v kategorii: 397
Url:converts-drawable-to-bitmap
Share
Share
Tweet