我想放大一个布局,把它画到96x96位图上,然后把它发送给MetaWatch,它的96x96黑白屏幕上没有的灰度级。事实上,我已经设法做到了,但我并不满足于这样的结果:字符要么太大,要么太薄,无法读取。
如果我将视图呈现到96x96位图上,就会在一个很小的屏幕上看到非常大的字母:
public void sendView(View v) {
Bitmap bm = createViewBitmap(v, 1, 1);
sendLcdBitmap(bm);
bm.recycle();
}如果我将视图呈现到更大的位图上,并通过调用sendViewScaled(R.layout.test_layout, 1, 4)对其进行缩放,则缩放后的文本看起来不太好。也就是说,它可能更小,但如果我让它变小,它会变得太薄。
public void sendViewScaled(View v, int num, int denom) {
Bitmap bm = createViewBitmap(v, num, denom);
Bitmap bm2 = Bitmap.createScaledBitmap(bm, SCREEN_SIZE, SCREEN_SIZE, false);
sendLcdBitmap(bm2);
bm2.recycle();
bm.recycle();
}
public void sendViewScaled(int id, int num, int denom) {
sendViewScaled(inflateView(id), num, denom);
}将视图转换为位图的函数是:
protected Bitmap createViewBitmap(View v, int num, int denom) {
v.measure(MeasureSpec.makeMeasureSpec(SCREEN_SIZE*num/denom, MeasureSpec.EXACTLY)
,MeasureSpec.makeMeasureSpec(SCREEN_SIZE*num/denom, MeasureSpec.EXACTLY)
);
Bitmap b = Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(b);
c.setDensity(Bitmap.DENSITY_NONE);//DisplayMetrics.DENSITY_xxx;
v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
v.draw(c);
return b;
}函数sendLcdBitmap()使用以下函数将ARGB_8888转换为单位位图:
protected boolean isRatherWhite(int color) {
return Color.red(color)+Color.green(color)+Color.blue(color) > 127*3;
//return color == Color.WHITE;
}因此,问题是:
我想在96x96位图上呈现一个类似R.layout.test_layout 的布局,B&W,没有灰度级。我怎样才能获得好的品质?
相关问题:
Converting a view to Bitmap without displaying it in Android?
getMeasuredWidth returns totally wrong value
How to Resize a Bitmap in Android?
How to convert Views to bitmaps?
http://www.skoumal.net/en/android-how-draw-text-bitmap
更新:使用isRatherWhite()中使用的值会有所帮助。
发布于 2014-10-08 13:39:06
我想你的问题是缩小比例。您可以尝试不同的算法,如这里提到的算法:What is the best image downscaling algorithm (quality-wise)?
https://stackoverflow.com/questions/26258067
复制相似问题