我正在使用Android-V11开发一个RDP客户端应用。
服务器:屏幕被分成4个部分,并将图像数据以byte[]形式发送给客户端。每帧的left、top、right、bottom以及屏幕分辨率(宽度--> 1024/1280,高度--? 768/1024)的值都会发送给客户端。
客户端:我正在使用Surface View来显示从服务器接收到的图像。我需要将4个框架(一个服务器屏幕)精确地适配到平板电脑屏幕上。
示例代码:
class mySurfaceView extends SurfaceView implements SurfaceHolder.Callback
{
class TutorialThread extends Thread
{
@Override
public void run()
{
Canvas c = null;
// Socket commnuication
......
Bitmap bmp;
while(true){
c=null;
//logic to get the details from server
.....
bmp = BitmapFactory.decodeByteArray(imageBytes, 0,imageBytes.length);
//Logic to calculate the Top Left, right bottom corners to divide the tablet screen into 4parts for 4 frames receiving from server
.....
//Frame rectangle for each frame
Rect rect = new Rect(newLeft, newTop,newWidth,newHeight);
//display image
try{
c = _surfaceHolder.lockCanvas(rect);
if(c!=null){
synchronized (_surfaceHolder)
{
c.drawBitmap(scaledBitmap, newLeft,newTop, paint);
}
}
}
finally{
if(c!=null){ _surfaceHolder.unlockCanvasAndPost(c);
}
}
//End of while
}
//End of run()
}
//End Tutorial Thread
}
//End of surfaceView
}
我们无法完全适配位图到矩形中。在平板电脑上显示的帧之间存在间隙。
调试代码后,我们发现检索到的位图(bmp)宽度为514,而矩形(rect)宽度为640。所以,位图不适合矩形中。
请问如何缩放位图以完全适配矩形。
注意:我还需要捏合缩放图像。
谢谢 & 问候 Yamini.