Create Image From View Screen Android
WebView_webview = (WebView)findViewById(R.id.webViewMapa);
_webview.getSettings().setBuiltInZoomControls(true);
_webview.setBackgroundColor(Color.parseColor("#E8EAE8"));
// _webview.loadUrl( ... some your page
Bitmap b = Bitmap.createBitmap(_webview.getWidth()/2, _webview.getHeight(), Bitmap.Config.ARGB_8888);
// you can to draw on bitmap
Canvas c = new Canvas(b);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setStrokeWidth(15.f);
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.STROKE);
//paint.setShadowLayer(5.f, 0, 5.f, 0xFF000000);
_webview.draw(c); // put into canvas content of view like image
c.drawLine(70, 0, 150, 350, paint);// draw some line
//Rect oval = new Rect(0, 0, 100, 100);
//c.drawArc(oval, 0, 180, false, paint);
// you can show bitmap in other view
((ImageView)findViewById(R.id.imageView1)).setImageBitmap(b);
396LW NO topic_id
AD
Další témata ....(Topics)
Codec, compress(), CompressFormat, quality, decodeByteArray(), Android example source code with image.
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.GRAY);
// you need to insert some image flower_blue into res/drawable folder
Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.flower_blue);
// Best of quality is 80 and more, 3 is very low quality of image
Bitmap bJPGcompress = codec(b, Bitmap.CompressFormat.JPEG, 3);
// get dimension of bitmap getHeight() getWidth()
int h = b.getHeight();
canvas.drawBitmap(b, 10,10, paint);
canvas.drawBitmap(bJPGcompress, 10,10 + h + 10, paint);
}
}
}
First cteate big icon 512x512 px formtat .PGN in graphics editor as Photoshop, Gimp, Piant.NET and save image.
If you create new project via Eclipse and choice your 512x512 image for ic_launcher.
Eclipse will make all icons from this image for new application very well.
If you create new project via Eclipse and choice your 512x512 image for ic_launcher.
Eclipse will make all icons from this image for new application very well.
How set rounded corners and own styles ActivityMy.java
\res\drawable\back_button_answer.xml
Button btn.setBackgroundResource(R.drawable.back_button_answer);
\res\drawable\back_button_answer.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="//schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners android:radius="10dip" />
<!-- background -->
<gradient
android:startColor="#D6D7D6"
android:centerColor="#E2E2E2"
android:centerY="0.75"
android:endColor="#D6D7D6"
android:angle="270"
/>
<stroke android:width="2dip" android:color="#fff"/>
</shape>
Integer, Float, String, List passed as reference in JAVA example source code:
// List passed as reference JAVA
List<Integer>list = new ArrayList<Integer>();
public void fc (List<Integer>listRef){
listRef.add(7);
listRef.add(5);
}
fc(list); // 7, 5
// String passed as reference JAVA
public void mutate(AtomicReference<Object> ref) { ref.set("Goodbye"); }
AtomicReference<Object> ref = new AtomicReference<Object>("Hello");
mutate(ref);
System.out.println(ref.get()); //Goodbye!
String s = (String) ref.get();
// Integer passed as reference JAVA
private static void mutate(AtomicReference<Object> ref) { ref.set(7); }
//public static void main(String[] arg) {
AtomicReference<Object> ref = new AtomicReference<Object>(5);
mutate(ref);
System.out.println(ref.get()); // 7
int n = (Integer) ref.get();
// Float passed as reference JAVA
private static void mutate(AtomicReference<Object> ref) { ref.set(14.8f); }
//public static void main(String[] arg) {
AtomicReference<Object> ref = new AtomicReference<Object>(12.1f);
mutate(ref);
float f = (Float) ref.get();
System.out.println(f); //14.8
Try insert + before R.drawable.xxxx
// error
InputStream is = context.getResources().openRawResource(R.drawable.app_sample_code);
// ok
InputStream is = context.getResources().openRawResource(+R.drawable.app_sample_code);
Editace: 2013-07-08 07:38:23
Počet článků v kategorii: 396
Url:create-image-from-view-screen-android