ShowLoClippingTiff.vb
''
'' This code is part of GrapeCity Documents for Imaging samples.
'' Copyright (c) GrapeCity, Inc. All rights reserved.
''
Imports System.IO
Imports System.Drawing
Imports System.Collections.Generic
Imports System.Linq
Imports System.Numerics
Imports GrapeCity.Documents.Drawing
Imports GrapeCity.Documents.Text
Imports GrapeCity.Documents.Imaging

'' This sample demonstrates how to find and show pixels with clipped shadows.
'' This sample is identical to ShowLoClippingJpeg but uses a TIFF image
'' rather than a JPEG created from the same source photo.
Public Class ShowLoClippingTiff
    Function GenerateImage(
            Optional pixelWidth As Integer = 1024,
            Optional pixelHeight As Integer = 1024,
            Optional opaque As Boolean = True,
            Optional dpiX As Single = 96,
            Optional dpiY As Single = 96) As GcBitmap
        Dim bmp = New GcBitmap(pixelWidth, pixelHeight, opaque, dpiX, dpiY)
        Using bmpSrc = New GcBitmap(Path.Combine("Resources", "ImagesBis", "clivia.tiff"))
            '' BitBlt requires the opacity of both images to be the same:
            bmpSrc.Opaque = opaque
            '' Render source image onto the target bitmap
            '' (generally we might want to resize the source image first,
            '' but in this case we just know that the source image has
            '' the same size as the target, so skip this step):
            bmp.BitBlt(bmpSrc, 0, 0)

            Using g = bmp.CreateGraphics()
                For i = 0 To bmp.PixelWidth - 1
                    For j = 0 To bmp.PixelHeight - 1
                        '' If all of the colors are 0x00, we change the pixel's color to magenta:
                        If (bmp(i, j) And &HFFFFFF) = 0 Then
                            bmp(i, j) = &HFFFF00FFUI
                        End If
                    Next
                Next
                '' Draw the original image in the bottom right corner for reference:
                Dim rc = New RectangleF(0, 0, pixelWidth / 4, pixelHeight / 4)
                g.DrawImage(bmpSrc, rc, Nothing, ImageAlign.StretchImage)
                g.DrawRectangle(rc, Color.LightGray)
            End Using
        End Using
        Return bmp
    End Function
End Class