Hi,
I made up the following to demonstrate what I meant.
In this example when you press the trackball/dpad center button the
view is written to a png file and also set as the wallpaper.
You can change it to save as jpeg file etc.
Hope that helps.
Regards
/////////////////////////////////////////////
package com.testSaveView;
import android.app.Activity;
import android.os.Bundle;
import java.io.FileOutputStream;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
public class testSaveView extends Activity
{
SomeView sv = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
sv = new SomeView(this);
setContentView( sv );
}
@Override
public boolean onKeyDown( int keyCode, KeyEvent event)
{
switch( event.getKeyCode() )
{
case KeyEvent.KEYCODE_DPAD_CENTER:
if ( sv != null )
{
saveView( sv );
return true;
}
default:
}
return super.onKeyDown( keyCode, event );
}
private void saveView( View view )
{
Bitmap b = Bitmap.createBitmap( view.getWidth(), view.getHeight
(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas( b );
view.draw( c );
FileOutputStream fos = null;
try {
fos = new FileOutputStream( "/sdcard/some_view_image_"
+ System.currentTimeMillis() + ".png" );
if ( fos != null )
{
b.compress(Bitmap.CompressFormat.PNG, 100, fos );
fos.close();
}
setWallpaper( b );
} catch( Exception e )
{
Log.e("testSaveView", "Exception: " + e.toString() );
}
}
class SomeView extends View
{
public SomeView( Context context )
{
super( context );
}
public void onDraw( Canvas canvas )
{
canvas.drawARGB(0x80, 0xff, 0, 0 );
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setTextSize( 48 );
canvas.drawText("...Some view...", 10, canvas.getHeight() / 2,
paint);
}
}
}
//////////////////////////
& the manifest -
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.testSaveView"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/
app_name">
<activity android:name=".testSaveView"
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>
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.SET_WALLPAPER"></
uses-permission>
</manifest>
On Sep 23, 7:12 pm, limtc <[email protected]> wrote:
> Mmm... I don't quite understand. The link you sent is the
> documentation for View?
>
> If I have a new canvas, what happened to the canvas in onDraw? And
> when should I call view.draw(canvas)?
>
> Do you have any sample codes? Appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---