nativescript-bitmap-factory
nativescript-bitmap-factory copied to clipboard
How to draw image on bmp?
I see functions to draw Arc, Circle, Line, Oval, Rect, but can not see function to draw bitmap. Is there any way to draw an existing image on bitmap?
I was able to accomplish this with something like:
(TypeScript)
const existingSrc = fromResource('existing_image');
const mutable = BitmapFactory.makeMutable(existingSrc);
let imgSrc;
BitmapFactory.asBitmap(mutable).dispose((bmp) => {
imgSrc = bmp.toImageSource();
});
You can insert an image into the bitmap
(Javascript)
import {Folder, path, knownFolders} from "tns-core-modules/file-system";
import BitmapFactory from "nativescript-bitmap-factory"
import { ImageSource, fromFileOrResource, fromFile } from "image-source";
const appFolder = knownFolders.currentApp();
const logoPath = path.join(appFolder.path, "assets/images/ExistingLogoImage.png");
const logoImgSource = fromFile(logoPath);
var bmp = BitmapFactory.create(300, 300);
bmp.dispose(function(b) {
b.insert(logoImgSource, "25,25");
const newImageSource = b.toImageSource();
const saved = resizedImageSource.saveToFile(filePath, "jpeg", 50);
if (saved) {
console.log("Image saved successfully! Path:",filePath);
}
});