Android. How to re-size a Bitmap to fit the screen in SurfaceView -
I would like to set the background image in my SurfaceView, but I can not get it on the scale of the screen. How do I set it?
My current code:
import android.content.Context; Import Android.graphics. Bitmap; Import and roid.graphics.BitmapFactory; Import Android.graphics. Canvas; Import android.graphics.Matrix; Import android.util.AttributeSet; Import android.view.SurfaceHolder; Import android.view.SurfaceView; Public Square MySpace has enhanced Surfaceview's executions: Runnabal {Surface Holder Our Holder; Thread ourThread = null; Boolean isRunning = true; Bitmap background; Bitmap claude; Public Mysore (Reference Reference) {Super (Reference); Init (reference); } Public MySpace (Reference Reference, AttributeSet attrs) {super (references, attrs); Init (reference); } Public MySpace (Reference Reference, AttributeSet attrs, int defStyle) {super (references, attrs, defStyle); Init (reference); } Private Zero init (reference reference) {// What goods that were in your original constructor ... ourHolder = getHolder (); Our thread = new thread (this); OurThread.start (); Background = bitmapfirenet Decode resources (getResources (), ArdraVable. Iceland); Clouda = BitmapFinder Decode Resources (getResources (), Armowwat.cloda); } Public zero breaks () {} Public Zero Resume () {} @ Override Public Wide Run () {/ TODO Automatically generated method stub while (hiring) {if (OurHolder.getSurface (.) IsValid ()) Ongoing ; Canvas canvas = ourHolder.lockCanvas (); Canvas.draw bitmap (background, 0, 0, empty); Canvas LeftBitmap (Cloud, 0, 0, empty); OurHolder.unlockCanvasAndPost (canvas); }} I have tried to apply the top answer, but I do not understand how to use the matrix.
To scale the bitmap in the size of the serverview
/ / The following two are just for viewing, they should anywhere SurfaceView targetSurfaceView; Bitmap mySourceBitmap; Bitmap ScalchedBitmap = Bitmap.comSetSchedleBitmap (mySourceBitmap, targetSurfaceView.getWidth), Target FieldFolder View.getHeight (), True); Then the method you use to attract:
secure entry onda (canvas canvas) {super. Don (canvas); Paint paint = new paint (); Canvas.drawBitmap (Scalbitmap, 0, 0, Paint); } Hope this helps
Comments
Post a Comment