本文整理了Java中android.graphics.Bitmap.writeToParcel()
方法的一些代码示例,展示了Bitmap.writeToParcel()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bitmap.writeToParcel()
方法的具体详情如下:
包路径:android.graphics.Bitmap
类名称:Bitmap
方法名:writeToParcel
暂无
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldWriteToParcelAndReconstruct() {
Bitmap bitmapOriginal;
int originalWidth = 10;
int originalHeight = 10;
bitmapOriginal = Bitmap.createBitmap(originalWidth, originalHeight, Bitmap.Config.ARGB_8888);
Parcel parcel = Parcel.obtain();
bitmapOriginal.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
Bitmap bitmapReconstructed = Bitmap.CREATOR.createFromParcel(parcel);
// get reconstructed properties
int reconstructedHeight = bitmapReconstructed.getHeight();
int reconstructedWidth = bitmapReconstructed.getWidth();
//compare bitmap properties
assertThat(originalHeight).isEqualTo(reconstructedHeight);
assertThat(originalWidth).isEqualTo(reconstructedWidth);
assertThat(bitmapOriginal.getConfig()).isEqualTo(bitmapReconstructed.getConfig());
int[] pixelsOriginal = new int[originalWidth * originalHeight];
bitmapOriginal.getPixels(pixelsOriginal, 0, originalWidth, 0, 0, originalWidth, originalHeight);
int[] pixelsReconstructed = new int[reconstructedWidth * reconstructedHeight];
bitmapReconstructed.getPixels(pixelsReconstructed, 0, reconstructedWidth, 0, 0,
reconstructedWidth, reconstructedHeight);
assertThat(Arrays.equals(pixelsOriginal, pixelsReconstructed)).isTrue();
}
代码示例来源:origin: trezor/trezor-android
@Override
protected void doWrite(Bitmap value, int flags) {
value.writeToParcel(parcel, flags);
}
代码示例来源:origin: stackoverflow.com
//Store
Parcel parcel = Parcel.obtain();
Bitmap sourceBitmap = Bitmap.createBitmap(200, 400, Config.ARGB_8888);
sourceBitmap.writeToParcel(parcel, 0);
//Retrieve
parcel.setDataPosition(0);
Bitmap destinationBitmap = Bitmap.CREATOR.createFromParcel(parcel);
代码示例来源:origin: fennifith/Status
if (largeIcon != null) {
dest.writeByte((byte) 1);
largeIcon.writeToParcel(dest, flags);
} else dest.writeByte((byte) 0);
代码示例来源:origin: stackoverflow.com
// Setup to get a mutable bitmap less than 40 Kbytes
String path = "someSmallImage.jpg";
Bitmap bm0 = BitmapFactory.decodeFile(path);
// Need it mutable to change height
Bitmap bm1 = bm0.copy(bm0.getConfig(), true);
// Chop it to get a size less than 40K
bm1.setHeight(bm1.getHeight() / 32);
// Now we have a BitMap with size < 40K for the test
Bitmap bm2 = bm1.copy(bm0.getConfig(), true);
// What's the parcel size?
Parcel p1 = Parcel.obtain();
bm2.writeToParcel(p1, 0);
// Expect byteCount and allocatedByteCount to be the same
Log.i("Demo", String.format("byteCount=%d allocatedByteCount=%d parcelDataSize=%d",
bm2.getByteCount(), bm2.getAllocationByteCount(), p1.dataSize()));
// Resize to make byteCount and allocatedByteCount different
bm2.setHeight(bm2.getHeight() / 4);
// What's the parcel size?
Parcel p2 = Parcel.obtain();
bm2.writeToParcel(p2, 0);
// Show that byteCount determines size of data written to parcel
Log.i("Demo", String.format("byteCount=%d allocatedByteCount=%d parcelDataSize=%d",
bm2.getByteCount(), bm2.getAllocationByteCount(), p2.dataSize()));
p1.recycle();
p2.recycle();
代码示例来源:origin: stackoverflow.com
bm.writeToParcel(p, 0);
代码示例来源:origin: rockon999/LeanbackLauncher
if (_result3 != null) {
reply.writeInt(1);
_result3.writeToParcel(reply, 1);
return true;
代码示例来源:origin: MoMoWait/LeanbackLauncher
if (_result3 != null) {
reply.writeInt(1);
_result3.writeToParcel(reply, 1);
} else {
reply.writeInt(0);
内容来源于网络,如有侵权,请联系作者删除!