是否有可能通过点击按钮来调整图像的方案?有可能、按钮、图像、方案

由网友(弑天杀戮)分享简介:我初步显示出一个空的观点。当我点击添加图片按钮,它显示了一组图像在网格然后我点击的图像上。我把图像中的视图通过动态地添加ImageView的使用拖动层。就这样,我加入了更多的图像。现在我想以编程方式调整每一个形象。可能吗?请提供code,如果它是可能的。I am initially showing an empty...

我初步显示出一个空的观点。当我点击添加图片按钮,它显示了一组图像在网格然后我点击的图像上。我把图像中的视图通过动态地添加ImageView的使用拖动层。就这样,我加入了更多的图像。现在我想以编程方式调整每一个形象。可能吗?请提供code,如果它是可能的。

I am initially showing an empty view. When I click on the "Add Image" button it shows a group of images in a grid then I click on an image. I am placing image in the view by adding the ImageView dynamically using Drag Layer. In this way I am adding more Images. Now I want to resize each of the image programmatically. Is it possible? Please provide the code if it is possible.

推荐答案

您可以使用下面的code,以调整图像大小。如果你知道图片的路径和需要的宽度和高度

You can use the following code to resize an image. if you know the image path and required width and height

public static Bitmap resizeBitMapImage1(String filePath, int targetWidth,
            int targetHeight) {
        Bitmap bitMapImage = null;
        // First, get the dimensions of the image
        Options options = new Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeFile(filePath, options);
        double sampleSize = 0;
        // Only scale if we need to
        // (16384 buffer for img processing)
        Boolean scaleByHeight = Math.abs(options.outHeight - targetHeight) >= Math
                .abs(options.outWidth - targetWidth);

        if (options.outHeight * options.outWidth * 2 >= 1638) {
            // Load, scaling to smallest power of 2 that'll get it <= desired
            // dimensions
            sampleSize = scaleByHeight ? options.outHeight / targetHeight
                    : options.outWidth / targetWidth;
            sampleSize = (int) Math.pow(2d,
                    Math.floor(Math.log(sampleSize) / Math.log(2d)));
        }

        // Do the actual decoding
        options.inJustDecodeBounds = false;
        options.inTempStorage = new byte[128];
        while (true) {
            try {
                options.inSampleSize = (int) sampleSize;
                bitMapImage = BitmapFactory.decodeFile(filePath, options);

                break;
            } catch (Exception ex) {
                try {
                    sampleSize = sampleSize * 2;
                } catch (Exception ex1) {

                }
            }
        }

        return bitMapImage;
    }

谢谢 迪帕克

Thanks Deepak

阅读全文

相关推荐

最新文章