我喜欢调整位图的大小,如果它很大,让它小,并将其放置在表面视图中的特定位置,我需要获得设备的宽度和高度,然后位图大小,并将它们放置在表面视图中,然后采取另一个图像调整大小,并将其放置在任何我喜欢的位置。如何首先知道坐标的位置(放置第二张图像-如果不应更改较大/较小的屏幕布局,则应与设备无关)
以及如何缩放一个大的位图并设置为背景,以便我可以在其上绘制图像。我的代码:
final int canvasWidth = getWidth();
final int canvasHeight = getHeight();
int imageWidth = img.getWidth();
int imageHeight = img.getHeight();
float scaleFactor = Math.min( (float)canvasWidth / imageWidth,
(float)canvasHeight / imageHeight );
Bitmap scaled = Bitmap.createScaledBitmap( img,
(int)(scaleFactor * imageWidth),
(int)(scaleFactor * imageHeight),
true );
canvas.drawColor(Color.BLACK);
canvas.drawBitmap(scaled, 10, 10, null);这缩放了大图像,但它不适合整个屏幕"img - bitmap就像一个背景图像“
有人可以帮助我理解调整大小的基础知识(我是新手,所以很难理解调整大小)来调整图像大小以适应屏幕,并将任何图像调整为较小的图像,并将其放置在我喜欢的任何位置。
发布于 2011-11-25 19:40:52
将位图存储为操作源,并使用ImageView显示它:
Bitmap realImage = BitmapFactory.decodeFile(filePathFromActivity.toString());
Bitmap newBitmap = scaleDown(realImage, MAX_IMAGE_SIZE, true);
imageView.setImageBitmap(newBitmap);
//scale down method
public static Bitmap scaleDown(Bitmap realImage, float maxImageSize,
boolean filter) {
float ratio = Math.min(
(float) maxImageSize / realImage.getWidth(),
(float) maxImageSize / realImage.getHeight());
int width = Math.round((float) ratio * realImage.getWidth());
int height = Math.round((float) ratio * realImage.getHeight());
Bitmap newBitmap = Bitmap.createScaledBitmap(realImage, width,
height, filter);
return newBitmap;
}并将ImageView的宽度和高度设置为"fill_parent“。
https://stackoverflow.com/questions/8268517
复制相似问题