The easiest way to do it is to do like you said... create a 2nd image
and read pixel by pixel from one to the other. However, that is
*VERY* processor intensive and with large images will take a VERY long
time to complete... so that is not the recommended way to do it.
The fastest way to do it, which is a little more memory intensive, but
MUCH quicker and much easier on the processor is to create a new
image, then render the border into the new image along with the old
image... and then save the results. Here's the source code on how to
do that (fully error checked and commented):
================================================
Option Explicit
Private Sub Form_Load()
Const IMAGE_LOAD_PATH As String = "C:\TEST.BMP"
Const IMAGE_SAVE_PATH As String = "C:\OUTPUT.BMP"
Const BORDER_WIDTH As Long = 5
Const BORDER_COLOR As Long = vbWhite
Dim objAIL As cAdvancedImagery
Dim hIMG As Long
Dim hIMG_New As Long
Dim hBMP As Long
Dim hBMP_Old As Long
Dim hMemDC As Long
Dim lngWidth As Long
Dim lngHeight As Long
' Initialize the AIL library
Set objAIL = New cAdvancedImagery
' Load the image
If objAIL.IO_LoadImage(IMAGE_LOAD_PATH, hIMG) = True Then
' Get the image's dimentions
lngWidth = objAIL.Info_Width(hIMG)
lngHeight = objAIL.Info_Height(hIMG)
' Increase the dimentions to accomidate a border on all sides of
the image
lngWidth = lngWidth + (BORDER_WIDTH * 2)
lngHeight = lngHeight + (BORDER_WIDTH * 2)
' Create a new image with the new dimentions
If objAIL.IO_CreateNew(hIMG_New, lngWidth, lngHeight, 32) = True
Then
' Create a Device Context (DC) to work with
If objAIL.MemoryDC_Create(hMemDC) = True Then
' Insert the new image into the newly created DC
If objAIL.MemoryDC_InsertImage(hMemDC, hIMG_New, hBMP_Old)
= True Then
' We don't need the new image anymore, so delete it
Call objAIL.IO_DestroyImage(hIMG_New)
' Fill the background with the background color
If objAIL.MemoryDC_FillRectangle(hMemDC, 0, 0,
lngWidth, lngHeight, , , vbTransparent, BORDER_COLOR, vbFSSolid) =
True Then
' Render the image onto the DC
If objAIL.Render_Normal(hIMG, hMemDC, BORDER_WIDTH,
BORDER_WIDTH) = True Then
' We don't need the original image anymore, so
delete it
Call objAIL.IO_DestroyImage(hIMG)
' Put the old BITMAP back into the DC, which
pulls out the new BITMAP
If objAIL.MemoryDC_InsertBitmap(hMemDC, hBMP_Old,
hBMP) = True Then
' Since the old BITMAP is now back in the DC,
we can get rid of it's handle
hBMP_Old = 0
' We don't need the memory DC anymore, so
clean it up
Call objAIL.MemoryDC_Destroy(hMemDC)
' Convert the new BITMAP to an image
If objAIL.Convert_BitmapToImage(hBMP,
hIMG_New) = True Then
' We don't need the BITMAP anymore, so
delete it
Call objAIL.IO_DestroyBitmap(hBMP)
' Save the image to file
If objAIL.IO_SaveImage(hIMG_New,
IMAGE_SAVE_PATH, IF_BMP, BMP_DEFAULT, True) = True Then
' DONE!
MsgBox "Successfully added border to
image", vbOKOnly Or vbInformation, ""
Else
MsgBox "Error converting new BITMAP to
an Image", vbOKOnly Or vbExclamation, " Error"
End If
' Don't need the new image anymore, so
clean it up
Call objAIL.IO_DestroyImage(hIMG_New)
Else
MsgBox "Error converting new BITMAP to an
Image", vbOKOnly Or vbExclamation, " Error"
End If
' Clean up the BITMAP
If hBMP <> 0 Then
Call objAIL.IO_DestroyBitmap(hBMP)
End If
Else
MsgBox "Error returning old BITMAP to DC",
vbOKOnly Or vbExclamation, " Error"
End If
Else
MsgBox "Error rendering image into DC", vbOKOnly
Or vbExclamation, " Error"
End If
Else
MsgBox "Error filling DC with background color",
vbOKOnly Or vbExclamation, " Error"
End If
Else
MsgBox "Error inserting image into DC", vbOKOnly Or
vbExclamation, " Error"
End If
' Clean up the DC
If hMemDC <> 0 Then
Call objAIL.MemoryDC_Destroy(hMemDC, hBMP_Old)
End If
Else
MsgBox "Error creating DC", vbOKOnly Or vbExclamation, "
Error"
End If
' Clen up image
If hIMG_New <> 0 Then
Call objAIL.IO_DestroyImage(hIMG_New)
End If
Else
MsgBox "Error creating new image", vbOKOnly Or vbExclamation,
" Error"
End If
' Clen up image
If hIMG <> 0 Then
Call objAIL.IO_DestroyImage(hIMG)
End If
Else
MsgBox "Error loading image file", vbOKOnly Or vbExclamation, "
Error"
End If
' Clean up AIL
Set objAIL = Nothing
End Sub
================================================
--- In AIL_Development@yahoogroups.com, "nick_hebb" <nick_hebb@...> wrote:
>
> I'm reading a bitmap in from the clipboard, and I want to add a white
> border around the edges. The only way that I can see to do it is to
> create a new image in memory that is slightly larger, and loop through
> each pixel in the existing image and set the pixels one by one in the
> new image with an offset.
>
> Is there an easier, built-in way to do this?
>
> Thanks,
>
> Nick
>