Custom dimensions from Canvas Snapshot #2513
Replies: 1 comment
-
Skia version: 1.3.9 Update: const makeImageSnapshot = useCallback(async () => {
const pixelRatio = LayoutHelper.pixelRatio;
let image;
const skImage = await canvasRef.current?.makeImageSnapshotAsync()!;
// I check if the dimensions are exactly divided by pixel ratio in iOS.
if (canvasSize.width % pixelRatio === 0 && canvasSize.height % pixelRatio === 0) || Platform.OS === 'android') {
image = skImage;
} else {
image = drawAsImageFromPicture(skImage, { width: canvasSize.width, height: canvasSize.height });
}
} export const drawAsImageFromPicture = (skImage: SkImage, canvasSize: Size) => {
const pixelRatio = LayoutHelper.pixelRatio;
const surface = Skia.Surface.MakeOffscreen(canvasSize.width * pixelRatio, canvasSize.height * pixelRatio)!;
const canvas = surface.getCanvas();
canvas.drawImage(skImage, 0, 0);
surface.flush();
return surface.makeImageSnapshot();
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Thank you for this great project.
I need custom dimensions for Instagram (1080 x 566, 1080 x 1350, 320 x 320) etc.
I know my canvas dimensions are multiplied by PixelRatio.get(). This value can be 2, 3 or 3.5.
How can I guarantee the user the expected dimensions?
Beta Was this translation helpful? Give feedback.
All reactions