CopyPastor

Detecting plagiarism made easy.

Score: 0.7559556365013123; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2017-09-25
by Vishrut Mavani

Original Post

Original - Posted on 2014-07-25
by Christopher Reichel



            
Present in both answers; Present only in the new answer; Present only in the old answer;

i think it will help you. Bitmap scaleBitmap = scaleBitmap(bitmap); RectF rectF = new RectF(0, (mHeight scaleBitmap.getHeight()), scaleBitmap.getWidth(), scaleBitmap.getHeight()); canvas.drawBitmap(scaleBitmap, null, rectF, null); private Bitmap scaleBitmap(Bitmap bm) { int width = bm.getWidth(); int height = bm.getHeight(); Log.v("Pictures", "Width and height are " + width + "--" + height); int mWidth = this.getResources().getDisplayMetrics().widthPixels; int mHeight = this.getResources().getDisplayMetrics().heightPixels; if (width > height) { // landscape int ratio = width / mWidth; width = mWidth; height = height / ratio; } else if (height > width) { // portrait int ratio = height / mHeight; height = mHeight; width = width / ratio; } else { // square height = mWidth; width = mWidth; } Log.v("Pictures", "after scaling Width and height are " + width + "--" + height); bm = Bitmap.createScaledBitmap(bm, width, height, true); return bm; }
Here I have a tested solution where I create a scaled Bitmap out of a bitmap file:
int scaleSize =1024; public Bitmap resizeImageForImageView(Bitmap bitmap) { Bitmap resizedBitmap = null; int originalWidth = bitmap.getWidth(); int originalHeight = bitmap.getHeight(); int newWidth = -1; int newHeight = -1; float multFactor = -1.0F; if(originalHeight > originalWidth) { newHeight = scaleSize ; multFactor = (float) originalWidth/(float) originalHeight; newWidth = (int) (newHeight*multFactor); } else if(originalWidth > originalHeight) { newWidth = scaleSize ; multFactor = (float) originalHeight/ (float)originalWidth; newHeight = (int) (newWidth*multFactor); } else if(originalHeight == originalWidth) { newHeight = scaleSize ; newWidth = scaleSize ; } resizedBitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, false); return resizedBitmap; }
Notice that I need scaled Bitmaps which have a maximum size of 4096x4096 Pixels but the aspect ratio needs to be kept while resizing. If you need other values for width or height just replace the values "4096".
This is just an addition to the answer of Coen but the problem in his code is the line where he calculates the ratio. Dividing two Integers gives an Integer and if the result is < 1 it will be rounded to 0. So this throws the "divide by zero" exception.

        
Present in both answers; Present only in the new answer; Present only in the old answer;