Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Image.java
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8package org.skia.jetski;
9
10import androidx.annotation.Nullable;
11import java.io.InputStream;
12
13public class Image {
14 private long mNativeInstance;
15
16 /**
17 * Construct an Image from encoded (PNG, GIF, etc) data.
18 *
19 * Returns null for unsupported formats or invalid data.
20 */
21 public static Image fromEncoded(byte[] encodedData) {
22 long nativeImage = nCreate(encodedData);
23 return nativeImage != 0
24 ? new Image(nativeImage)
25 : null;
26 }
27
28 /**
29 * Construct an Image from an encoded data stream.
30 *
31 * Returns null for unsupported formats or invalid stream.
32 */
33 public static Image fromStream(InputStream encodedStream) throws java.io.IOException {
34 byte[] encodedData = new byte[encodedStream.available()];
35 encodedStream.read(encodedData);
36
37 return fromEncoded(encodedData);
38 }
39
40 public int getWidth() {
41 return nGetWidth(mNativeInstance);
42 }
43
44 public int getHeight() {
45 return nGetHeight(mNativeInstance);
46 }
47
49 return makeShader(tmx, tmy, sampling, null);
50 }
51
53 @Nullable Matrix localMatrix) {
54 long nativeMatrix = localMatrix != null ? localMatrix.getNativeInstance() : 0;
55 return new Shader(nMakeShader(mNativeInstance, tmx.nativeInt, tmy.nativeInt,
56 sampling.getNativeDesc(),
57 sampling.getCubicCoeffB(), sampling.getCubicCoeffC(),
58 nativeMatrix));
59 }
60
61 /**
62 * Releases any resources associated with this Paint.
63 */
64 public void release() {
65 nRelease(mNativeInstance);
66 mNativeInstance = 0;
67 }
68
69 @Override
70 protected void finalize() throws Throwable {
71 release();
72 }
73
74 // package private
75 Image(long nativeInstance) {
76 mNativeInstance = nativeInstance;
77 }
78
79 // package private
80 long getNativeInstance() { return mNativeInstance; }
81
82 private static native long nCreate(byte[] encodedData);
83 private static native void nRelease(long nativeInstance);
84
85 private static native int nGetWidth(long nativeInstance);
86 private static native int nGetHeight(long nativeInstance);
87
88 private static native long nMakeShader(long nativeInstance, int tmx, int tmy, int samplingDesc,
89 float samplingCoeffB, float samplingCoeffC,
90 long nativeMatrix);
91}
Shader makeShader(TileMode tmx, TileMode tmy, SamplingOptions sampling, @Nullable Matrix localMatrix)
Definition Image.java:52
static Image fromStream(InputStream encodedStream)
Definition Image.java:33
long getNativeInstance()
Definition Image.java:80
Shader makeShader(TileMode tmx, TileMode tmy, SamplingOptions sampling)
Definition Image.java:48
static Image fromEncoded(byte[] encodedData)
Definition Image.java:21
Image(long nativeInstance)
Definition Image.java:75
SkTileMode tmy
SkTileMode tmx