nativescript-community / nativescript-drawingpad

:pencil: NativeScript plugin to provide a way to capture any drawing (signatures are a common use case) from the device
Apache License 2.0
90 stars 32 forks source link

Bitmap size (Android) #30

Closed kwong93 closed 6 years ago

kwong93 commented 6 years ago

When getting the Bitmap of the drawing, the size is different depending on the device used. For example:

10 inch tablet (Verizon Ellipses) Width: 563 Height: 165

Samsung Galaxy S7 Width: 1500 Height: 440

I am guessing the native library is using the pixel density of the device S7: 577 ppi tablet: 224 ppi

Any way to resize the bitmap so it stays consistent?

kwong93 commented 6 years ago

I just wrote some function to resize, works for now

function resize(sourceImage, targetWidth) {
    var sourceWidth = sourceImage.getWidth();
    if (sourceWidth < targetWidth) {
        return null;
    }
    var sourceHeight = sourceImage.getHeight();
    var adjustedHeight = (targetWidth * sourceHeight) / sourceWidth;
    var resizedImage = android.graphics.Bitmap.createScaledBitmap(sourceImage, targetWidth, adjustedHeight, true);
    return resizedImage;
}