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.

Compressing converting a bitmap to PNG format Android example



public class MainActivity extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static Bitmap codec(Bitmap src, Bitmap.CompressFormat format,
			int quality) {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		src.compress(format, quality, os);

		byte[] array = os.toByteArray();
		return BitmapFactory.decodeByteArray(array, 0, array.length);
	}

	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);
            
        
			Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.flower_blue);
             
			Bitmap bPNGcompress = codec(bmp, Bitmap.CompressFormat.PNG, 0);

		   int h = bmp.getHeight();
           
           canvas.drawBitmap(bmp, 10,10, paint);
           canvas.drawBitmap(bPNGcompress, 10,10 + h + 10, paint);
           
		}

	}
}


397LW NO topic_id



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


112

How to capture screenshot of emulator window - Android sample | how-to-capture-screenshot-of-emulator-window-android-sample


When Eclipse and the emulator runs.
To access the DDMS perspective, go to Window > Open Perspective > DDMS. If DDMS does not appear, go to Window > Open Perspective > Other ... and select DDMS.

Open Devices TAB. Window -> Show view -> Devices

From Devices TAB select Screen Capture
Android emlator screen capture by eclipse
187

Get the color of a specific pixel Java Android example | get-the-color-of-a-specific-pixel-java-android-example



             ImputStream      is = this.getResources().openRawResource(R.drawable.colors);
             Bitmap    mBitmap2 = BitmapFactory.decodeStream(is);
        
         int  w = mBitmap2.getWidth();
         int  h = mBitmap2.getHeight();
//  int x , y have to be smaller as w , h 
         int _color =  mBitmap2.getPixel(x, y);

270

setTesting(boolean) from the type AdRequest is deprecated | settestingboolean-from-the-type-adrequest-is-deprecated


Admob testing on emulator issue.
Android Eclipse code warning:
setTesting(boolean) from the type AdRequest is deprecated
Solution:
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);


AdView adView = new AdView(this, AdSize.BANNER, "a14d9..........");//MY_AD_UNIT_ID
AdRequest adRequest = new AdRequest();
		adRequest.setTesting(true); // deprecated

		adRequest.addTestDevice(AdRequest.TEST_EMULATOR); // OK
		adView.loadAd(adRequest);

226

Eclipse my templates store Android | eclipse-my-templates-store-android


Where file(s) does eclipse store Java code style settings to?
If you need copy any old templates to the new workspace.

workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.ui.prefs


You can edit the Eclipse Templates from menu Window - Preferences - Java - Editor - Templates.
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>


Editace: 2013-12-09 13:09:31
Počet článků v kategorii: 397
Url:compressing-converting-a-bitmap-to-png-format-android-example
Share
Share
Tweet