Re: How to remove a frame/border around a picture?
If the borders are of a fixed width simply use StretchBlt (or similar): https://docs.microsoft.com/en-us/win...gdi-stretchblt to copy the bordered portion of the image to a new image. If the borders are of a variable width you will need to manually scan the image line by line. This will probably be a slow and tedious process though.
EDIT:
I dont know the color of thickness of the frame/border.
I overlooked that part, sorry. If you're interested I have something written in vb.net that might work. EDIT: see my last post.
Last edited by Peter Swinkels; Jan 31st, 2022 at 03:44 AM.
Re: How to remove a frame/border around a picture?
Originally Posted by Mith
I dont know the color of thickness of the frame/border.
I assume you already know about the appropriate CutOut (Blit-, Crop-, PaintPicture-calls) -
and that the main-problem is, to determine the Line-thickness (or if there is one at all)?
If yes, a relative fast working approach would be, to just "walk" a few pixels from each side of the image
(I'd start in the middle on each side, then walk towards the center - that's a bit more reliable than the corners)
And since these are only a few "Pixel-Checks" (4 or 5 on each side) -
you can even use the relatively slow VB6-Point(x,y) function to get the ColorValue.
E.g. I've downloaded your Bear-Image with the black border -
placed it in: "c:\temp\bear.bmp" and get a bordersize of 3 on each side, this way:
Code:
Private Sub Form_Load()
Dim P As VB.PictureBox, i As Long
Set P = Controls.Add("VB.PictureBox", "picAnalyze") 'let's use an invisible, Autoredraw-PicBox for analyzing
Set P.Picture = LoadPicture("c:\temp\bear.bmp")
P.BorderStyle = 0: P.ScaleMode = vbPixels
P.AutoSize = True: P.AutoRedraw = True
Dim UBx: UBx = P.ScaleWidth - 1
Dim UBy: UBy = P.ScaleHeight - 1
For i = 0 To 3
Debug.Print Get4BitColor(P.Point(UBx \ 2, i)) 'walk from Top downwards (in the middle of the img-width)
Debug.Print Get4BitColor(P.Point(UBx \ 2, UBy - i)) 'walk from Bottom upwards (in the middle of the img-width)
Debug.Print Get4BitColor(P.Point(i, UBy \ 2)) 'walk from left to right (in the middle of the img-height)
Debug.Print Get4BitColor(P.Point(UBx - i, UBy \ 2)) 'walk from right to left (in the middle of the img-height)
Next
End Sub
Private Function Get4BitColor(Color) As Long
Dim S6 As String, R4 As Byte, G4 As Byte, B4 As Byte
S6 = Right("000000" & Hex$(Color), 6) 'ensure 6 hex-digits
R4 = CByte("&H" & Mid$(S6, 5, 2)) \ 2 ^ 4
G4 = CByte("&H" & Mid$(S6, 3, 2)) \ 2 ^ 4
B4 = CByte("&H" & Mid$(S6, 1, 2)) \ 2 ^ 4
Get4BitColor = RGB(R4 * 2 ^ 4, G4 * 2 ^ 4, B4 * 2 ^ 4)
End Function
The Get4BitColor is used, to account for slight color-differences in the potential BorderColor
(e.g. from JPG-Encoding).