为什么我的第一张drawbitmap无法正常工作,但我的第二张有三分之一呢?我得到的只是第一个黑屏,但其他人画得很好。
FULL_COMPOSITE_SIZE = new Size(1920, 1080);
PREVIEW_COMPOSITE_SIZE = new Size(640, 360);
SCREEN_POSITION = new RectF(0.645833F, 0.037037F, 0.979167F, 0.37037F);
SCALE_PAINT = new Paint();
SCALE_PAINT.setFilterBitmap(true);
SCALE_PAINT.setDither(true);
SCREEN_PAINT = new Paint(SCALE_PAINT);
SCREEN_PAINT.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SCREEN));
Bitmap bitMain = BitmapFactory.decodeFile(mlsPaths.get(miPosition));
Size sWhole = FULL_COMPOSITE_SIZE;
Bitmap bitWhole = Bitmap.createBitmap(sWhole.Width, sWhole.Height, Bitmap.Config.ARGB_8888);
Canvas cBuild = new Canvas(bitWhole);
int i = (int)((sWhole.Height - bitMain.getHeight() * (sWhole.Width / bitMain.getWidth())) / 2.0F);
cBuild.drawBitmap(bitMain, null, new Rect(0, i, sWhole.Width, sWhole.Height - i), SCALE_PAINT);
bitMain.recycle();
cBuild.drawBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.vignette_overlay), null, new Rect(0, 0, sWhole.Width, sWhole.Height), SCALE_PAINT);
cBuild.drawBitmap(BitmapFactory.decodeFile(mlsPaths.get(miPosition + 1)), null, new Rect(Math.round(SCREEN_POSITION.left * sWhole.Width), Math.round(SCREEN_POSITION.top * sWhole.Height), Math.round(SCREEN_POSITION.right * sWhole.Width), Math.round(SCREEN_POSITION.bottom * sWhole.Height)), SCREEN_PAINT);
提前致谢
这是运行此代码,然后保存图像和刷新视图的日志输出。
01-06 00:24:42.965 16870-16870/com.w9jds.glassshare D/dalvikvm﹕ GC_FOR_ALLOC freed 4624K, 34% free 15883K/23815K, paused 40ms
01-06 00:24:43.075 16870-16870/com.w9jds.glassshare I/dalvikvm-heap﹕ Grow heap (frag case) to 33.477MB for 18767888-byte allocation
01-06 00:24:43.137 16870-16872/com.w9jds.glassshare D/dalvikvm﹕ GC_CONCURRENT freed <1K, 19% free 34210K/42183K, paused 5ms+10ms
01-06 00:24:43.817 16870-16870/com.w9jds.glassshare D/dalvikvm﹕ GC_FOR_ALLOC freed 34K, 19% free 34178K/42183K, paused 18ms
01-06 00:24:43.832 16870-16870/com.w9jds.glassshare I/dalvikvm-heap﹕ Grow heap (frag case) to 41.355MB for 8294416-byte allocation
01-06 00:24:43.856 16870-16872/com.w9jds.glassshare D/dalvikvm﹕ GC_CONCURRENT freed <1K, 16% free 42278K/50311K, paused 2ms+4ms
01-06 00:24:43.879 16870-16870/com.w9jds.glassshare D/dalvikvm﹕ GC_FOR_ALLOC freed 18328K, 53% free 23950K/50311K, paused 20ms
01-06 00:24:43.887 16870-16870/com.w9jds.glassshare I/dalvikvm-heap﹕ Grow heap (frag case) to 31.368MB for 8294416-byte allocation
01-06 00:24:43.950 16870-16870/com.w9jds.glassshare D/dalvikvm﹕ GC_FOR_ALLOC freed 0K, 37% free 32050K/50311K, paused 20ms
01-06 00:24:43.965 16870-16870/com.w9jds.glassshare D/dalvikvm﹕ GC_FOR_ALLOC freed 0K, 37% free 32051K/50311K, paused 20ms
01-06 00:24:44.004 16870-16870/com.w9jds.glassshare I/dalvikvm-heap﹕ Grow heap (frag case) to 49.166MB for 18662416-byte allocation
01-06 00:24:44.036 16870-16872/com.w9jds.glassshare D/dalvikvm﹕ GC_CONCURRENT freed 0K, 27% free 50276K/68551K, paused 3ms+5ms
01-06 00:24:44.317 16870-16870/com.w9jds.glassshare D/dalvikvm﹕ GC_FOR_ALLOC freed 26325K, 66% free 23983K/68551K, paused 20ms
01-06 00:24:44.371 16870-16870/com.w9jds.glassshare I/dalvikvm-heap﹕ Grow heap (frag case) to 41.387MB for 18767888-byte allocation
01-06 00:24:44.411 16870-16872/com.w9jds.glassshare D/dalvikvm﹕ GC_CONCURRENT freed <1K, 39% free 42310K/68551K, paused 3ms+5ms
01-06 00:24:45.411 16870-16870/com.w9jds.glassshare D/dalvikvm﹕ GC_FOR_ALLOC freed 18367K, 66% free 23984K/68551K, paused 19ms
01-06 00:24:45.418 16870-16870/com.w9jds.glassshare I/dalvikvm-heap﹕ Grow heap (frag case) to 31.400MB for 8294416-byte allocation
01-06 00:24:45.457 16870-16872/com.w9jds.glassshare D/dalvikvm﹕ GC_CONCURRENT freed <1K, 54% free 32084K/68551K, paused 3ms+5ms
01-06 00:24:45.629 584-4706/? I/DirectoryTracker﹕ File [1388989485633.jpg] ADDED to [/mnt/sdcard/DCIM/Camera]
01-06 00:24:45.629 468-554/? I/DirectoryTracker﹕ File [1388989485633.jpg] ADDED to [/mnt/sdcard/DCIM/Camera]
01-06 00:24:45.629 692-1830/? I/DirectoryTracker﹕ File [1388989485633.jpg] ADDED to [/mnt/sdcard/DCIM/Camera]
01-06 00:24:46.473 373-456/? D/dalvikvm﹕ GC_FOR_ALLOC freed 93K, 15% free 9263K/10823K, paused 22ms
01-06 00:24:46.504 373-375/? D/dalvikvm﹕ GC_CONCURRENT freed 9K, 10% free 9760K/10823K, paused 2ms+3ms
01-06 00:24:46.668 16870-16870/com.w9jds.glassshare D/CardScrollView﹕ Activating.
01-06 00:24:46.731 16870-16889/com.w9jds.glassshare D/dalvikvm﹕ GC_FOR_ALLOC freed 8708K, 65% free 24092K/68551K, paused 27ms
01-06 00:24:46.746 16870-16889/com.w9jds.glassshare I/dalvikvm-heap﹕ Grow heap (frag case) to 28.070MB for 4691984-byte allocation
01-06 00:24:46.786 16870-16870/com.w9jds.glassshare D/dalvikvm﹕ GC_FOR_ALLOC freed <1K, 59% free 28673K/68551K, paused 26ms
01-06 00:24:46.832 16870-16870/com.w9jds.glassshare D/SliderMenuView﹕ Performed action on 0 : true
01-06 00:24:46.848 109-203/? D/audio_hw_primary﹕ select_output_device: output_type: 1, base_headset_volume: 1
01-06 00:24:46.856 16870-16872/com.w9jds.glassshare D/dalvikvm﹕ GC_CONCURRENT freed 5714K, 67% free 22962K/68551K, paused 3ms+6ms
01-06 00:24:46.950 206-467/? W/Resources﹕ Converting to boolean: TypedValue{t=0x3/d=0xc4c "res/anim/decelerate_interpolator.xml" a=1 r=0x10a0006}
01-06 00:24:47.551 16870-16888/com.w9jds.glassshare D/dalvikvm﹕ GC_FOR_ALLOC freed 12758K, 84% free 11448K/68551K, paused 34ms
01-06 00:24:47.590 16870-16888/com.w9jds.glassshare I/dalvikvm-heap﹕ Grow heap (frag case) to 15.722MB for 4691984-byte allocation
01-06 00:24:47.629 16870-16872/com.w9jds.glassshare D/dalvikvm﹕ GC_CONCURRENT freed 2K, 77% free 16028K/68551K, paused 3ms+8ms
01-06 00:24:48.137 16870-16894/com.w9jds.glassshare D/dalvikvm﹕ GC_FOR_ALLOC freed 4649K, 82% free 12621K/68551K, paused 23ms
01-06 00:24:48.137 16870-16894/com.w9jds.glassshare I/dalvikvm-heap﹕ Grow heap (frag case) to 14.372MB for 2073616-byte allocation
01-06 00:24:48.168 16870-16872/com.w9jds.glassshare D/dalvikvm﹕ GC_CONCURRENT freed <1K, 79% free 14646K/68551K, paused 4ms+7ms
01-06 00:24:48.809 206-230/? D/PowerManagerService﹕ setTimeoutLocked now=76562486 when=76568486 currentTimeoutOverride=-1 nextTimeoutOverride=-1 currentState=3 nextState=1
答案 0 :(得分:0)
替换:
bitMain = BitmapFactory.decodeFile(mlsPaths.get(miPosition)):
使用:
Bitmap.Config mBitmapConfig;
mBitmapConfig = Bitmap.Config.ARGB_8888;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = mBitmapConfig;
bitMain = BitmapFactory.decodeFile(mlsPaths.get(miPosition), options);