Hello,
I'm working on an android application where I've created a custom view like this:
It's basicly just draws a path on the screen which i get thru the constructor. It's a graph of some values I get from an XML.
I insert the view inside a HorizontalScrollView in my layout like this:
Yeah I know I shouldn't be using AbsoluteLayout but I might change that later.
Now I want to be able to save this BitmapGraf with the drawn path and the background and all that to a png or jpg or anything but I can't wrap my head around it.
I've looked on several sites on how to convert views to bitmaps but I can't get it to work...
Anyone who can help me please!? I'm somewhat desperate.
/Raffe
I'm working on an android application where I've created a custom view like this:
Code:
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;
public class BitmapGraf extends View {
private Paint grafFarg;
private static Path grafPath = null;
public BitmapGraf(Context context, AttributeSet attrs) {
super(context, attrs);
grafFarg = new Paint();
grafFarg.setAntiAlias(true);
grafFarg.setColor(Color.RED);
}
public static void skickaPath(Path nyPath) {
grafPath = new Path();
grafPath = nyPath;
}
@Override
public void onDraw(Canvas canvas) {
if (grafPath != null) {
canvas.drawPath(grafPath, grafFarg);
}
}
}
I insert the view inside a HorizontalScrollView in my layout like this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button android:id="@+id/ButtonOppna"
android:text="@string/button_tidigare"
android:layout_height="40dip"
android:layout_x="5dip"
android:layout_y="225dip"
android:layout_width="170dip"
/>
<Button android:id="@+id/ButtonSkicka"
android:text="@string/button_skicka"
android:layout_height="40dip"
android:layout_width="100dip"
android:layout_x="375dip"
android:layout_y="225dip"
/>
<HorizontalScrollView android:id="@+id/HScrollView"
android:layout_x="5dip"
android:layout_y="10dip"
android:layout_width="470dip"
android:layout_height="210dip">
<se.doconnet.android.andning.BitmapGraf
android:layout_width="640dip"
android:layout_height="205dip"
android:background="@drawable/graf"
/>
</HorizontalScrollView>
</AbsoluteLayout>
Now I want to be able to save this BitmapGraf with the drawn path and the background and all that to a png or jpg or anything but I can't wrap my head around it.
I've looked on several sites on how to convert views to bitmaps but I can't get it to work...
Anyone who can help me please!? I'm somewhat desperate.
/Raffe