Wednesday, February 26, 2014

Consult android image processing techniques


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:
references, 4th Floor xidianstudent reply:
final analysis, the picture did a scaling algorithm!

Find detailed algorithm code
Reply:
reference to the second floor youngc527 reply:
create 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 ...


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:
reference to the 8th floor BuleRiver reply:
create an empty Bitmap, and then use that to create a bitmap canvas after scaling the original image, drawn on the canvas .


Share the code
Reply:
reference to the second floor youngc527 reply:
create 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 ...

 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:
reference to the second floor youngc527 reply:
create 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 ...

drawBitmap method to draw up the original, did not find the similar parameter

Reply:
reference to the second floor youngc527 reply:
create 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 ...

 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 void OnDraw (Canvas canvas) {
Bitmap bg = Bitmap.createBitmap (
BitmapFactory.decodeResource (getResources (), R.drawable.abc),
0, 0, 800, 480) ;/ / 800 * 480 background image
Bitmap bitmap = BitmapFactory.decodeResource (getResources (),
R.drawable.canvas_top) ;/ / target picture
canvas = new Canvas (bg);
canvas.save (Canvas.ALL_SAVE_FLAG);
canvas.restore ();
int width = bitmap.getWidth ();
int height = bitmap.getHeight ();
tochange (bitmap, width / 2, height / 2) ;/ / target image compression
canvas.drawBitmap (bitmap, 0, 0, paint);

}

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:
reference to the 12th floor xiaobeiweng reply:
Quote: references to the second floor youngc527 reply:

Creating Bitmap
of a 800 × 480Bitmap bitmap = Bitmap.createBitmap ...

 public class MyView extends View {
...
}

Is not this, but does not show
test



reference to the 10th floor u010749756 reply:
Quote: references to the second floor youngc527 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:
reference to the 13th floor youngc527 reply:
Quote: references to the 12th floor xiaobeiweng reply:

Quote: references to the second floor youngc527 reply:

Creating Bitmap
of a 800 × 480Bitmap bitmap = Bitmap.createBitmap ...

 public class MyView extends View {
...
}

Is not this, but does not show
test



reference to the 10th floor u010749756 reply:
Quote: references to the second floor youngc527 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;
}

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