Cannot rescale bitmap
Date : March 29 2020, 07:55 AM
I hope this helps you . I am tring to implement "extend" button to fit image into chosen boundaries. public static Bitmap resizeBitmap(Bitmap photo, float x, float y) {
try {
// get current bitmap width and height
int width = photo.getWidth();
int height = photo.getHeight();
// determine how much to scale
float scaleWidth = x / width;
float scaleHeight = y / height;
// create the matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bitmap
matrix.postScale(scaleWidth, scaleHeight);
// recreate the new bitmap
Bitmap resizebitmap = Bitmap.createBitmap(photo, 0, 0, width,
height, matrix, false);
return resizebitmap;
} catch (NullPointerException e) {
e.printStackTrace();
} catch (OutOfMemoryError e) {
e.printStackTrace();
System.gc();
}
return null;
}
|
OutOfMemory Error when trying to rescale a Bitmap
Tag : android , By : Tim Benninghoff
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Please have a look at my related question: High resolution Image - OutOfMemoryErrorpublic Bitmap scaleDownBitmap(Bitmap photo, int newHeight) {
final float densityMultiplier = getResources().getDisplayMetrics().density;
int h= (int) (newHeight*densityMultiplier);
int w= (int) (h * photo.getWidth()/((double) photo.getHeight()));
photo = Bitmap.createScaledBitmap(photo, w, h, true);
return photo;
}
ImageView.setImageBitmap(scaleDownBitmap(youroldbitmap, 300));
|
Android - Resource Bitmap uses more memory than Bitmap from file
Date : March 29 2020, 07:55 AM
I wish did fix the issue. I noticed something odd. If I open an image (1.6mb) from Drawable Resource, the app crashes with the OutOfMemory error, however, if I open the same image which is saved on SD Card, the app does not crash. , check this out :
|
How to examine the potential filesize/bitmap size before decoding the bitmap from file path in android?
Date : March 29 2020, 07:55 AM
|
Faster Bitmap Rescale
Tag : cpp , By : aspitzer
Date : March 29 2020, 07:55 AM
hope this fix your issue Refactored the function to apply your suggestions and enabled the SSE2 and fp:fast options. Performance increased by 3x: static int ReScale(char* srcBuffer, int srcLen, int srcStart, int srcStride, int srcHeight, VideoInfo::ePixelFormat srcPixelFormat,
char* dstBuffer, int dstLen, int dstStart, int dstStride, int dstHeight, VideoInfo::ePixelFormat dstPixelFormat, bool reverseCopy)
{
int srcPixelDepth = VideoInfo::GetPixelFormatSize(srcPixelFormat);
int srcWidth = static_cast<int>(floor(srcStride / static_cast<float>(srcPixelDepth)));
int dstPixelDepth = VideoInfo::GetPixelFormatSize(dstPixelFormat);
int dstWidth = static_cast<int>(floor(dstStride / static_cast<float>(dstPixelDepth)));
float resizeRatio = min(dstWidth / static_cast<float>(srcWidth), dstHeight / static_cast<float>(srcHeight));
int dstXOffset = static_cast<int>((dstWidth - (resizeRatio * srcWidth)) / 2.f);
int dstYOffset = static_cast<int>((dstHeight - (resizeRatio * srcHeight)) / 2.f);
ZeroMemory(dstBuffer + dstStart, dstLen);
srcBuffer += srcStart;
dstBuffer += dstStart;
dstWidth -= 2 * dstXOffset;
dstHeight -= 2 * dstYOffset;
int dstPixelOffset = 0;
int srcPixelOffset = 0;
int srcPixelYOffset = 0;
float srcPixelXOffset = 0;
float srcPixelXStride = 1 / resizeRatio;
int pixelDepthSize = min(srcPixelDepth, dstPixelDepth);
for (int y = 0; y < dstHeight; y++)
{
dstPixelOffset = dstXOffset * dstPixelDepth + (y + dstYOffset) * dstStride;
srcPixelYOffset = static_cast<int>(min(y / resizeRatio, srcHeight));
srcPixelYOffset = (reverseCopy ? (srcHeight - (srcPixelYOffset + 1)) : srcPixelYOffset) * srcStride;
srcPixelXOffset = 0;
for (int x = 0; x < dstWidth; x++)
{
srcPixelOffset = srcPixelYOffset + (static_cast<int>(min(srcPixelXOffset, srcWidth)) * srcPixelDepth);
if (srcPixelOffset + pixelDepthSize < srcLen && dstPixelOffset + pixelDepthSize < dstLen)
{
memcpy(dstBuffer + dstPixelOffset, srcBuffer + srcPixelOffset, pixelDepthSize);
}
dstPixelOffset += dstPixelDepth;
srcPixelXOffset += srcPixelXStride;
}
}
return 0;
}
|