多年老号跪求framebuffer里面RGBA_8888该如何输出的问题

hyl716 2014-03-04 11:18:48
目前在写一个android截图的代码,已经可以从framebuffer获取byte[]了问题是调用itmap.createBitmap入参 是一个int[]数组。不知道这里如何转换,网上找了一堆都没有发现RGBA_8888格式是什么规则。
代码如下:

// 获取显示方式
int pixelformat = display.getPixelFormat();
PixelFormat localPixelFormat1 = new PixelFormat();
PixelFormat.getPixelFormatInfo(pixelformat, localPixelFormat1);
int deepth = localPixelFormat1.bytesPerPixel;// 位深

byte[] piex = new byte[mheight * mwidth * deepth];
InputStream stream = getInputStream();
DataInputStream dStream = new DataInputStream(stream);
dStream.readFully(piex);

//问题就在这里piex是字节数组如何按RGBA_8888格式转换成int数组放入下面的方法啊?
Bitmap bitmap = Bitmap.createBitmap(?, mwidth, mheight,
Bitmap.Config.ARGB_8888);

...全文
415 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
QQ515311445 2015-01-23
  • 打赏
  • 举报
回复
引用 楼主 hyl716 的回复:
目前在写一个android截图的代码,已经可以从framebuffer获取byte[]了问题是调用itmap.createBitmap入参 是一个int[]数组。不知道这里如何转换,网上找了一堆都没有发现RGBA_8888格式是什么规则。 代码如下:

// 获取显示方式
		int pixelformat = display.getPixelFormat();
		PixelFormat localPixelFormat1 = new PixelFormat();
		PixelFormat.getPixelFormatInfo(pixelformat, localPixelFormat1);
		int deepth = localPixelFormat1.bytesPerPixel;// 位深

		byte[] piex = new byte[mheight * mwidth * deepth];
		InputStream stream = getInputStream();
		DataInputStream dStream = new DataInputStream(stream);
		dStream.readFully(piex);
		
		//问题就在这里piex是字节数组如何按RGBA_8888格式转换成int数组放入下面的方法啊?
		Bitmap bitmap = Bitmap.createBitmap(?, mwidth, mheight,
				Bitmap.Config.ARGB_8888);

framebuffer取数据是否需要root权限?
ouzhouren 2014-03-04
  • 打赏
  • 举报
回复
RGBA是数据的顺序,R表示red值、G表示green值、B表示blue,A表示透明度,也就是三原色+透明度。每个字母用一个字节表示,四个字母合成一个32bit的整数。所以,你看pixel数组的RGB顺序,然后合成RGBA格式就行了。例如,三原色的值分别用r,g,b变量表示,最后合成的值为rgba = (r << 24) | (g << 16) | (b << 8) | a,a通常为0。
hyl716 2014-03-04
  • 打赏
  • 举报
回复
感谢楼上的大牛回复。恕我愚钝,有几个问题想问下 1.ss.bpp这个值是从哪取得? 2.你的那个BUFFER是读哪的文件?是那个fb0吗 3.下面这段话有什么用? // handle the screen rotation int rot = getScreenRotation(); if (rot != 0) { Matrix matrix = new Matrix(); matrix.postRotate(-rot); bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true); } 还望不厌其烦,大牛教我,不胜感激!
媒体盒子 2014-03-04
  • 打赏
  • 举报
回复
请看下面一段代码


private void writeImageFile(Screenshot ss, String file) {
		if (ss == null || !ss.isValid())		throw new IllegalArgumentException();
		if (file == null || file.length() == 0)	throw new IllegalArgumentException();
		
		// resolve screenshot's BPP to actual bitmap pixel format
		Bitmap.Config pf;
		switch (ss.bpp) {
			case 16:	pf = Config.RGB_565; break;
			case 32:	pf = Config.ARGB_8888; break;
			default:	pf = Config.ARGB_8888; break;
		}

		// create appropriate bitmap and fill it wit data
		Bitmap bmp = Bitmap.createBitmap(ss.width, ss.height, pf);
		bmp.copyPixelsFromBuffer(ss.pixels);
		
		// handle the screen rotation
		int rot = getScreenRotation();
		if (rot != 0) {
			Matrix matrix = new Matrix();
			matrix.postRotate(-rot);
			bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
		}

		// save it in PNG format
		FileOutputStream fos;
		try {
			fos = new FileOutputStream(file);
		} catch (FileNotFoundException e) {
			throw new InvalidParameterException();
		}
		bmp.compress(CompressFormat.PNG, 100, fos);
	}
其中

	class Screenshot {
		public Buffer pixels;
		public int width;
		public int height;
		public int bpp;
		
		public boolean isValid() {
			if (pixels == null || pixels.capacity() == 0 || pixels.limit() == 0) return false;
			if (width <= 0 || height <= 0)	return false;
			return true;
		}
	}

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧