我有一个应用有两个RelativeViews,一个是Matchparent,250dp,一个是300dp,200dp。
它们初始化如下:
//These are global variables for the views
View mView;
View resizedView;
//These lines allow the user to draw to the RelativeViews, this code is on the onCreate
//SignatureView class courtesy of Square
mView = new SignatureView(activity, null);
resizedView = new SignatureView(activity, null);
layout.addView(mView, new LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
resized.addView(resizedView, new LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
我想要发生的是,在用户在较大的视图 (mView) 上绘制并按下按钮后,其缩放版本会出现在较小的视图 (resizedView) 中。
到目前为止,这就是我在按钮的 onClick 功能中所拥有的,但它不起作用。
//this code fetches the drawing from the larger view
Bitmap bitmap = Bitmap.createBitmap(mView.getWidth(),
mView.getHeight(), Bitmap.Config.ARGB_8888);
//this code resized it accordingly to a new bitmap
Bitmap resizedImage = Bitmap.createScaledBitmap(bitmap, 399, 266, true);
//this is my sad attempt on creating a canvas with the resized image
Canvas c = new Canvas(resizedImage);
c.drawColor(Color.WHITE);
c.drawBitmap(resizedImage, 0, 0, null);
//this is where I attempt to attach the scaled image to the smaller view
resizedView.draw(c);
//then I go resize it because I need to save/print it
ByteArrayOutputStream stream = new ByteArrayOutputStream();
resizedImage.compress(Bitmap.CompressFormat.PNG, 90, stream);
我在这里做错了什么?