我正在开发Android应用程序,它从相机中获取帧并在表面视图上显示,我使用相机回调来获取原始图像,然后将其转换为字节流并传递到服务器进行处理,然后服务器返回相同的帧。但问题是图像视图在绘制图像(位图)15-20 fps时非常慢。有没有其他解决方案使用我可以快速绘制位图。在当前代码中,我正在处理不同线程上的位图,并使用UI线程,我将位图设置为图像视图。
相机回调中的代码是
Camera.Size pSize = camera.getParameters().getPreviewSize();
YuvImage yuv = new YuvImage(data, ImageFormat.NV21,
pSize.width, pSize.height, null);
yuv.compressToJpeg(new Rect(0, 0, pSize.width,
pSize.height), 100, baos);
rawImage = baos.toByteArray();
Bitmap bitmap = BitmapFactory.decodeByteArray(rawImage,
0, rawImage.length);
bitmap = Util.getResizedBitmap(bitmap, frameResolution);
final ByteArrayOutputStream rotatedStream = new ByteArrayOutputStream();
bitmap = Util.RotateBitmap(bitmap, 90);
bitmap.compress(Bitmap.CompressFormat.WEBP, 100, rotatedStream);
baos.close();
rawImage = rotatedStream.toByteArray();
if(isStreamingStart== true) {
beforeTime=(new Date()).getTime();
if(client.isConnected()==false){
client.connect();
}
client.send(rawImage);
rotatedStream.flush();
}
和返回位图的代码是
decodedString = Base64.decode((String) data, Base64.DEFAULT);
byte[] dataString = ((String)data).getBytes();
String stringDecompressed = compressor.decompressToString(dataString);
byte[] imageAsBytes = stringDecompressed.getBytes();
final Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
final Bitmap mutableBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
final Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
HomeActivity.this.runOnUiThread(new Runnable() {
public void run() {
try {
remoteViewImageView.setImageBitmap(bitmap);
} catch (Exception e) {
e.printStackTrace();
}
}
});