nativescript-bitmap-factory
nativescript-bitmap-factory copied to clipboard
.rotate() function seems to return a blank image
So I am using the following code in a fairly simple view:
import * as Enums from "ui/enums";
import * as BitmapFactory from "nativescript-bitmap-factory";
let temp_path = global.temp_path;
let image = ImageSource.fromFile(temp_path);
let mutable_opts: BitmapFactory.IMakeMutableOptions = {
disposeCurrent: true,
temp: {
stradegy: BitmapFactory.TempFileStradegy.CacheDir,
}
};
BitmapFactory
.asBitmap(BitmapFactory.makeMutable(
image,
mutable_opts
)).dispose(function(b) {
var rotate = 90;
b = b.rotate(rotate);
image = b.toImageSource();
image.saveToFile(
temp_path,
Enums.ImageFormat.jpeg
);
});
FrameModule
.topmost()
.navigate({
moduleName: 'views/review/review',
clearHistory: true
});
The intention is to rotate the image and save it to a temp folder (temp_path) then we display it on a separate screen (views/review/review).
When I review the image I just get a blank screen (it looks like the image container is set but is not being filled with a rotated image).
I am using similar code, but with b.resize() instead of b.rotate() and that seems to work as expected.
I have recently upgraded to tns 2.5.0 and typescript 2.0.3 and also upgraded this module to 1.7.0, I am wondering if this might be related?
Many thanks for any assistance,
Mo
I get this too
In BitmapFactory.ios.js replace rotate function with this:
// [INTERNAL] _rotate()
iOSImage.prototype._rotate = function (degrees) {
radians = degrees * Math.PI / 180.0;
var oldImg = this._nativeObject;
try {
UIGraphicsBeginImageContext(oldImg.size);
var context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, oldImg.size.width / 2.0, oldImg.size.height / 2.0);
CGContextRotateCTM(context, radians);
oldImg.drawInRect(CGRectMake(-oldImg.size.width / 2.0, -oldImg.size.height / 2.0, oldImg.size.width, oldImg.size.height));
return UIGraphicsGetImageFromCurrentImageContext();
}
finally {
UIGraphicsEndImageContext();
}
};
Thanks for the fix @adfdev