ScanPicture Class
class ScanPicture : ScanningSdkLibrary.Instance
A page being scanned: its pixels, the document outline detected on it, and any text recognised from it.
The type every integration starts with. Load one from a file, a content URI, an asset or a bitmap, detect the document with detectCutout, straighten and clean it with refine, and write it out with an ImageWriter.
See also
Samples
import android.content.Context
import android.net.Uri
import com.pixelnetica.scanning.RefineFeature
import com.pixelnetica.scanning.ScanPicture
fun main() {
//sampleStart
ScanPicture(context, uri).use { page ->
val cutout = page.detectCutout()
page.refine(
listOf(
RefineFeature.Rectify.WithCutout(cutout),
RefineFeature.Profile(RefineFeature.Profile.Type.Bitonal),
),
)
}
//sampleEnd
}
Constructors
ScanPicture
@JvmOverloads constructor(context: Context, contentUri: Uri, compatMode: Boolean = false)
Loads a page from a content URI, such as one returned by the photo picker.
@JvmOverloads constructor(imageFile: File, compatMode: Boolean = false)
Loads a page from a file.
@JvmOverloads constructor(assets: AssetManager, path: String, compatMode: Boolean = false)
Loads a page from the application’s assets.
@JvmOverloads constructor(bitmap: Bitmap, metadata: Bundle = Bundle.EMPTY)
Creates a page from a bitmap your application already holds.
constructor(source: ScanPicture)
Creates an independent copy of another page, sharing no native state with it.
Types
Companion
object Companion
Loading pages from streams, files, assets, and content URIs.
Properties
colorHint
var colorHint: Int
A hint about the page’s colour content, used to pick processing defaults.
hasImage
val hasImage: Boolean
Whether this page holds real pixel data.
hasText
val ScanPicture.hasText: Boolean
Whether this page carries a recognition result.
orientation
var orientation: ScanOrientation
Which way up the page is.
pageNumber
var pageNumber: Int
The page’s position in a multi-page document, used when writing it out with ImageWriter.
scanText
var scanText: ScanText
The text recognised on this page.
scope
val scope: ScanCutout
An outline covering the whole page, for when no document has been detected.
shadows
var shadows: Boolean
Whether the page has shadowed or unevenly lit areas that processing should even out.
size
val size: Size
The size of the page in pixels.
Functions
close
@Synchronized open override fun close()
Releases the native memory held by this instance immediately instead of waiting for the garbage collector.
createBitmap
@JvmOverloads external fun createBitmap(flags: Int = 0, orientation: ScanOrientation = ScanOrientation.Undefined, outTransform: Matrix? = null): Bitmap
Renders the page into an Android bitmap for display.
detectCutout
external fun detectCutout(): ScanCutout
Finds the document in this page and returns its outline.
detectOrientation
external fun detectOrientation(detector: ScanDetector): Boolean
Works out which way up this page is and records the result in orientation.
display
fun ScanPicture.display()
Marks this page as the one currently displayed, so processing can favour on-screen quality.
read
@JvmOverloads external fun read(reader: ScanReader, callback: ScanReader.DisplayCallback? = null)
Recognises the text on this page.
rectify
fun ScanPicture.rectify(cutout: ScanCutout)
Crops and straightens the page to an outline, leaving its colours untouched.
refine
external fun refine(features: Iterable<RefineFeature>)
Processes this page in place, applying whichever of the features you pass.
resize
@JvmOverloads external fun resize(width: Int, height: Int, uniform: Boolean = false)
Scales this page to the given size, replacing its pixels.
resize
fun ScanPicture.resize(size: Size, uniform: Boolean = false)
Scales this page to the given size.
toString
open external override fun toString(): String
A readable summary of the page, for logging.
withOrientation
fun ScanPicture.withOrientation(newOrientation: ScanOrientation): ScanPicture
Returns this page at the given orientation.
write
external fun write(stream: OutputStream, packed: Boolean)
Writes the page to a stream in the SDK’s own format.