بروز خطا
[message]
اشتراک در سوال
رای ها
[dataList]
چطور bitmap را به []byte تبدیل کنم؟
سلام دوستان
من میخوام bitmap را به []byte تبدیل کنم لطفا راهنمایی کنید. البته نمی خوام از compression استفاده کنم
خودم کد زیر را نوشتم اما null بر میگردونه
public static byte[] getByteArrayFromBitmap(Bitmap bitmap) {
//calculate how many bytes our image consists of.
int bytes = bitmap.getByteCount();
//or we can calculate bytes this way. Use a different value than 4 if you don't use 32bit images.
//int bytes = b.getWidth()*b.getHeight()*4;
ByteBuffer buffer = ByteBuffer.allocate(bytes); //Create a new buffer
bitmap.copyPixelsToBuffer(buffer); //Move the byte data to the buffer
byte[] array = buffer.array(); //Get the underlying array containing the data.
return array;
}
برای این سوال 1 پاسخ وجود دارد.
پاسخ به سوال
هادی اکبرزاده
11 سال پیش
0
0
Bitmap bmp = intent.getExtras().get("data");
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
پاسخگویی و مشاهده پاسخ های این سوال تنها برای اعضای ویژه سایت امکان پذیر است .
چنانچه تمایل دارید به همه بخش ها دسترسی داشته باشید میتوانید از این بخش لایسنس این آموزش را خریداری نمایید .