简体   繁体   中英

How to crop an image converted to Uint8Array?

I have an image converted to base64-string. I convert base64-string to Uint8Array by code:

const BASE64_MARKER = ';base64,';
function convertDataURIToBinary(dataURI) {
  const base64Index = dataURI.indexOf(BASE64_MARKER) + BASE64_MARKER.length;
  const base64 = dataURI.substring(base64Index);
  const raw = window.atob(base64);
  const rawLength = raw.length;
  const array = new Uint8Array(new ArrayBuffer(rawLength));
  for (let i = 0; i < rawLength; i++) {
    array[i] = raw.charCodeAt(i);
  }
  return array;
}

I don't know how to crop it. Can you help me to implement the algorithm?

Thank you, mpm and YAHsaves. I decided to use canvas and it works easy and quickly. Here is the link to npm package . I hope, it can help other people to crop and resize images in browser using canvas.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM