开发者

Android: How to override density and just use pixels?

I’m using a canvas and bitmap to draw graphics such as circles, rects text etc and want my graphic routines to use actual pixels based on the true screen resolution in pixels just as one would on a PC graphics app. Clearly the Android OS is meant to use densities to try and give the user a good experience independent from the actual device screen size and resolutions. However when I give the command to set pixel x,y then it would be nice to actually have pixel x,y set and not have the system override my coordinates - is it possible to override the system to set pixel x,y?

For instance, if the screen is set for 320x480 (G1 or Hero) it works fine - but on a tablet(IMX515) with screen 800x600 the graphics are always stretched horizontally.

I have tried setting differing densities of Bitmap and Canvas but nothing works - on the tablet they are always stretched to fill the width of the screen. I have also tried in Manifest开发者_StackOverflow中文版

<supports-screens android:anyDensity=”true” />  

.

Here are some snippets of code based on a SurfaceView:—

(1) In the Bitmap create and setup (screenWidth, screenHeight are from metrics):-

backBitmap=Bitmap.createBitMap(screenWidth,screenHeight,Bitmap.config.ARGB_8888);

//backbitmap.setDensity(160)

backCanvas=new Canvas(backBitmap)

//backCanvas.setDensity(160);

.

(2) In the drawing routine:-

paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.RED); 
backCanvas.drawCircle(50,50,30,paint);

.

(3) In the Canvas onDraw method:-

protected void onDraw(Canvas canvas){
  if (drawingFlag==true){

    // canvas.setDensity(160)

     canvas.drawBitmap(backBitmap,0,0,null);
  }

}

. . * Solution ****** Its amazing how sloppy I was - I had been working with Media Player and left the following code in when the SurfaceView was created:-

holder=mySurfaceView.getHolder();
holder.setFixedSize(320,480);

This was forcing the drawing into the 320x480 then scaling across the screen. Changing as below fixed problem

holder.setFixedSize(800,600) 


. . * Solution ** Its amazing how sloppy I was - I had been working with Media Player and left the following code in when the SurfaceView was created:-

holder=mySurfaceView.getHolder();
holder.setFixedSize(320,480);

This was forcing the drawing into the 320x480 then scaling across the screen. Changing as below fixed problem

holder.setFixedSize(800,600)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜