nativescript-bitmap-factory icon indicating copy to clipboard operation
nativescript-bitmap-factory copied to clipboard

How to draw image on bmp?

Open thelastsummer opened this issue 6 years ago • 2 comments

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?

thelastsummer avatar Jan 25 '19 14:01 thelastsummer

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();
});

ChrisJohns-me avatar May 14 '19 16:05 ChrisJohns-me

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);
        }
      });

amarseelam avatar Oct 27 '19 00:10 amarseelam