Analogy: The specification of the picture is: 480 * 800's Then processed into specifications: 800 * 480 There is no feasible solution, as long as generate 800 * 480 format, the original picture without distortion on the line. Guiqiu expert!<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) -> Reply: You can customize the background Reply: Creating Bitmap of a 800 × 480Bitmap bitmap = Bitmap.createBitmap ... Create a Canvas Canvas canvas = new Canvas (bitmap) Calculate the middle position, the original drawing up canvas.drawBitmap ... If you need to save the bitmap into a JPG / PNG, selected high quality bitmap.compress ... Reply: 2nd Floor positive solutions, layout can be used ImageView, set the property to fitY, or center Reply: In the final analysis, is a picture made a scaling algorithm! Reply:
Find detailed algorithm code Reply:
Brother, can then elaborate Reply: Try this method
/ ** * Picture zoom * @ Param bigimage * @ Param newWidth * @ Param newHeight * @ Return * / public Bitmap tochange (Bitmap bigimage, int newWidth, int newHeight) { / / Get the image width and height int width = bigimage.getWidth (); int height = bigimage.getHeight (); Matrix object / / create an action picture with aMatrix matrix = new Matrix (); / / Calculate the zoom ratio, a new dimension in addition to the original size float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; / / Scale the image motion matrix.postScale (scaleWidth, scaleHeight); Bitmap bitmap = Bitmap.createBitmap (bigimage, 0, 0, width, height, matrix, true); return bitmap; }
Reply: Create an empty Bitmap, and then use that to create a bitmap canvas after scaling the original image, drawn on the canvas. Reply:
Share the code Reply:
Bitmap bitmap = Bitmap.createBitmap (800, 480, Config.ARGB_8888) ;/ / create a background of a 800 * 480! Canvas canvas = new Canvas (bitmap) ;/ / create a Canvas canvas.drawBitmap (bitmap, matrix, paint); / / artwork does not seem to be able to draw up a way
Reply:
drawBitmap method to draw up the original, did not find the similar parameter Reply:
public class MyView extends View {
private Paint paint; private Canvas canvas;
public MyView (Context context) { super (context); paint = new Paint (); paint.setAntiAlias (true); this.setKeepScreenOn (true); paint.setColor (Color.RED);
public Bitmap tochange (Bitmap bitmap, int newWidth, int newHeight) { int width = bitmap.getWidth (); int height = bitmap.getHeight (); Matrix matrix = new Matrix (); float scaleWidth = ((float) newWidth) / width; float scaleHeight = ((float) newHeight) / height; matrix.postScale (scaleWidth, scaleHeight); Bitmap bm = Bitmap.createBitmap (bitmap, 0, 0, width, height, matrix, true); return bm;
} }
This is not, but does not show the test Reply:
Creating Bitmap of a 800 × 480Bitmap bitmap = Bitmap.createBitmap ...
Bitmap bitmap = Bitmap.createBitmap (800, 480, Config.ARGB_8888) ;/ / create a background of a 800 * 480! Canvas canvas = new Canvas (bitmap) ;/ / create a Canvas canvas.drawBitmap (bitmap, matrix, paint); / / artwork does not seem to be able to draw up a way
private Bitmap scale (Bitmap origin) { Bitmap bitmap = Bitmap.createBitmap (800, 480, Config.ARGB_8888); Canvas canvas = new Canvas (bitmap); Rect target = null; int orgWidth = origin.getWidth (), orgHeight = origin.getHeight (); int bgHeight = bitmap.getHeight (), bgWidth = bitmap.getWidth (); if (orgWidth * bgHeight> orgHeight * bgWidth) { int newWidth = bgWidth, newHeight = newWidth * orgHeight / orgWidth; target = new Rect (0, (bgHeight - newHeight) / 2, newWidth, (bgHeight + newHeight) / 2); } Else { int newHeight = bgHeight, newWidth = newHeight * orgWidth / orgHeight; target = new Rect ((bgWidth - newWidth) / 2, 0, (bgWidth + newWidth) / 2, newHeight); } canvas.drawBitmap (origin, null, target, new Paint (Paint.DITHER_FLAG | Paint.FILTER_BITMAP_FLAG)); return bitmap; }
Reply:
Creating Bitmap of a 800 × 480Bitmap bitmap = Bitmap.createBitmap ...
public class MyView extends View { ... }
Is not this, but does not show
test
Creating Bitmap of a 800 × 480Bitmap bitmap = Bitmap.createBitmap ...
Bitmap bitmap = Bitmap.createBitmap (800, 480, Config.ARGB_8888) ;/ / create a background of a 800 * 480! Canvas canvas = new Canvas (bitmap) ;/ / create a Canvas canvas.drawBitmap (bitmap, matrix, paint); / / artwork does not seem to be able to draw up a way
private Bitmap scale (Bitmap origin) { Bitmap bitmap = Bitmap.createBitmap (800, 480, Config.ARGB_8888); Canvas canvas = new Canvas (bitmap); Rect target = null; int orgWidth = origin.getWidth (), orgHeight = origin.getHeight (); int bgHeight = bitmap.getHeight (), bgWidth = bitmap.getWidth (); if (orgWidth * bgHeight> orgHeight * bgWidth) { int newWidth = bgWidth, newHeight = newWidth * orgHeight / orgWidth; target = new Rect (0, (bgHeight - newHeight) / 2, newWidth, (bgHeight + newHeight) / 2); } Else { int newHeight = bgHeight, newWidth = newHeight * orgWidth / orgHeight; target = new Rect ((bgWidth - newWidth) / 2, 0, (bgWidth + newWidth) / 2, newHeight); } canvas.drawBitmap (origin, null, target, new Paint (Paint.DITHER_FLAG | Paint.FILTER_BITMAP_FLAG)); return bitmap; }
Really, really too thanks! If you add on the original drag, background static, how to achieve? Reply: Thanks to not give points, who are willing to control you ah! Reply:
No comments:
Post a Comment