Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何从现有位图创建更大的位图_Android_Image_Bitmap - Fatal编程技术网

Android 如何从现有位图创建更大的位图

Android 如何从现有位图创建更大的位图,android,image,bitmap,Android,Image,Bitmap,我有一个位图图像。如何以编程方式创建更大的位图?我尝试创建scaleBitMap,但它没有显示更大的 int newHeight=900; Bitmap bg1=Bitmap.createScaledBitmap(bg, width, newHeight, false); canvas.drawBitmap(bg1, null, new Rect(0, 0, getWidth(), newHeight), null); 如何解决此问题?也许您应该尝试以下方法: int newHeight=90

我有一个位图图像。如何以编程方式创建更大的位图?我尝试创建scaleBitMap,但它没有显示更大的

int newHeight=900;
Bitmap bg1=Bitmap.createScaledBitmap(bg, width, newHeight, false);
canvas.drawBitmap(bg1, null, new Rect(0, 0, getWidth(), newHeight), null);

如何解决此问题?

也许您应该尝试以下方法:

int newHeight=900;
int newWidth= bg.getWidth;
Bitmap bg1=Bitmap.createScaledBitmap(bg, newWidth, newHeight, true);

总是值得一试

也许你应该试试这个:

int newHeight=900;
int newWidth= bg.getWidth;
Bitmap bg1=Bitmap.createScaledBitmap(bg, newWidth, newHeight, true);

始终值得一试

位图。createScaledBitmap()正在做您想做的事情,问题是当您试图将其绘制到画布上时。getWidth()返回的是什么?发布代码的其余部分,为我们提供一些上下文,我们可以找到您的问题。

位图。createScaledBitmap()正在执行您想要的操作,问题是当您尝试将其绘制到画布时。getWidth()返回的是什么?发布代码的其余部分,为我们提供一些上下文,我们可以找到您的问题。

请尝试此代码

public Bitmap getResizeBitmap(Bitmap bitmap, int newHeight, int newWidth)
        {

            int width = bitmap.getWidth();
            int height = bitmap.getHeight();

            float scaleWidth = ((float)newWidth)/width;
            float scaleHeight = ((float)newHeight)/height;

            Matrix matrix = new Matrix();
            matrix.postScale(scaleWidth, scaleHeight);
            Bitmap resizeBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);

            return resizeBitmap;

        }
然后在onCreate方法中使用此

myImage = Bitmap.createBitmap(BitmapFactory
                    .decodeResource(this.getResources(), R.drawable.mypic));

            myImage.setDensity(1);

            imageview = (ImageView)findViewById(R.id.imageViewId);
            imageview.setImageBitmap(getResizeBitmap(myImage,195, 480));//as per as your requirement
请尝试此代码

public Bitmap getResizeBitmap(Bitmap bitmap, int newHeight, int newWidth)
        {

            int width = bitmap.getWidth();
            int height = bitmap.getHeight();

            float scaleWidth = ((float)newWidth)/width;
            float scaleHeight = ((float)newHeight)/height;

            Matrix matrix = new Matrix();
            matrix.postScale(scaleWidth, scaleHeight);
            Bitmap resizeBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);

            return resizeBitmap;

        }
然后在onCreate方法中使用此

myImage = Bitmap.createBitmap(BitmapFactory
                    .decodeResource(this.getResources(), R.drawable.mypic));

            myImage.setDensity(1);

            imageview = (ImageView)findViewById(R.id.imageViewId);
            imageview.setImageBitmap(getResizeBitmap(myImage,195, 480));//as per as your requirement

getWidth()表示屏幕的高度。getWidth()表示屏幕的高度。这是当使用scrollTo视图希望内部滚动其内容时不起作用这是当使用scrollTo视图希望内部滚动其内容时不起作用