Tuesday, May 20, 2014

[android-developers] off center alignment when saving PNG

I'm confused as to why the alignment changes when the View is saved

Here is my layout

<FrameLayout         android:layout_width="1000dp"  android:layout_height="707dp"  android:layout_marginLeft="140dp"  android:layout_marginTop="670dp"  android:id="@+id/home"  android:background="@color/black"  >
   <ImageView        android:layout_width="1000dp"  android:layout_height="707dp"  android:background="@color/brown"                  android:id="@+id/graphic"      android:src="@drawable/anatomy_hooves"  />    
   <com.TouchPanel   android:layout_width="1000dp"  android:layout_height="707dp"  android:background="@android:color/transparent"    android:id="@+id/touchLayer"   />
   <com.PenPanel     android:layout_width="1000dp"  android:layout_height="707dp"  android:background="@android:color/transparent"    android:id="@+id/penLayer"     />
</FrameLayout> 



Here is the code that saves

FrameLayout home                     = (FrameLayout)findViewById(R.id.home); home.layout(0, 0, 1500, 1061);
home.layout(0, 0, 1500, 1061);
home.setDrawingCacheEnabled(true);
Bitmap bmp = Bitmap.createBitmap(home.getDrawingCache());
Log.i("VISIT","Bitmap    " + bmp.getWidth() + " x " + bmp.getHeight() + "      " + bmp.getDensity()  );
try {
FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/DCIM/Images/" + skeletonFileName);
bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
out.flush();
out.close();
Log.i("INFO","saved Skeleton to   ["+ skeletonFileName +"] ");
} catch (Exception err) {
err.printStackTrace();
Log.e("INFO","Could Not save Skeleton to   ["+ skeletonFileName +"] ");
}
home.setDrawingCacheEnabled(false);



Here is the screen BEFORE pressing the save Button


Here is the resulting PNG file generated by executing the code


Why does the drawing shift  and rescale ?

What am I missing, how can I save the image as it appear on the screen


Thanks in advance

No comments:

Post a Comment