ShowHiClipping.vb
''
'' This code is part of Document Solutions for Imaging demos.
'' Copyright (c) MESCIUS 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 blown out highlights.
Public Class ShowHiClipping
    Function GenerateImage(
        ByVal pixelSize As Size,
        ByVal dpi As Single,
        ByVal opaque As Boolean,
        Optional ByVal sampleParams As String() = Nothing) As GcBitmap

        Dim bmp = New GcBitmap(pixelSize.Width, pixelSize.Height, opaque, dpi, dpi)
        Using bmpSrc = New GcBitmap(Path.Combine("Resources", "Images", "tudor.jpg"))
            '' 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
                        Dim px = bmp(i, j)
                        '' If any of the colors are 0xFF, we change the pixel's color to magenta:
                        If (px And &HFF) = &HFF Or (px And &HFF00) = &HFF00 Or (px And &HFF0000) = &HFF0000 Then
                            bmp(i, j) = &HFFFF00FFUI
                        End If
                    Next
                Next

                '' Draw the original image in the bottom right corner for reference:
                Dim sx = pixelSize.Width / 3, sy = pixelSize.Height / 3
                g.DrawImage(bmpSrc, New RectangleF(sx * 2, sy * 2, sx, sy), Nothing, ImageAlign.StretchImage)
            End Using
        End Using
        Return bmp
    End Function
End Class