Select the text of the text from Virlenecheng BLOG

xiaoxiao2021-03-06  78

Generally, the text is different from the picture, but they have a common point. The picture is made up of a point, and the color values ​​of these points can be composed of numbers, and text can be represented by the ASCII code, which makes numbers become a trench channel bridge between them. Therefore, you can hide the text into the picture.

This can be implemented in Visual Basic 6.0. First we turn the text into a number, then take out the RGB value of each point in the picture, add each three of each three to the R value, G value, B value, and subtract, Then, the RGB value is restored to the point in the picture, so we have hidden the text into the picture. What should I do if I want to take out text? We can compare the source image with the target picture, and the difference in the difference is converted to text, and the restore of the text is realized.

Specific method: first create form files FRMPICTETEXT.FRM and module file modpicturetext.bas

Module file:

Public Declare Function GetObject Lib "GDI32" Alias ​​"getObjecta" (Byval_

HOBJECT As Long, LPOBJECT AS ANY) AS Long

'Pixel used to get pictures

Public Declare Function Getpixel LIB "GDI32" (byval HDC As Long, Byval X _

As long, byval y as long) AS long 'is used to get the RGB value of the image specified point

Public Type Bitmap

BMTYPE AS long

BMWIDTH AS long

Bmheight as long

BMWIDTHBYTES AS Long

BMPLANES AS INTEGER

BMBITSPIEL AS INTEGER

BMBITS As Long

End Type

Function HEXDEC (Number As String) AS Integer 'Transforms hexadecimal to decimal

Dim n as integer, DEC AS STRING, TMP AS INTEGER

For n = 1 to Len (Number)

Dec = MID (Number, N, 1)

IF ASC (DEC)> = 65 THEN

Dec = ucase (DEC)

Dec = Format (ASC (DEC) - 55)

END IF

TMP = VAL (DEC) * 16 ^ (Len (Number) - N)

HEXDEC = HEXDEC TMP

Next n

END FUNCTION

Form file: Create two picture boxes: picsource is used to display source pictures, Picobject is used to display target pictures,

Establish two text boxes: txtSource is used to display the source text, txtObject is used to display the restored text, and set to each multi-line display, create two command buttons: cmdTextTopicture is used to hide the text into the picture, cmdpictTureTExT is used to restore text.

Private sub flow_load ()

Picsource.Autoredraw = true: picobject.autoredraw = true

picsource.autosize = true: picobject.autosize = true

Picsource.picture = loadingPicture ("c: /test.bmp")

Picobject.height = picsource.height 'Sets the Height and Picobject.width = Picsource.Width' width property of the target picture box, guarantee

'The size of the target picture is the same as the source file

End Sub

Private subduDTextTopicture_click ()

DIM NUMX AS INTEGER, CHRTMP AS STRING, NUMTMP AS INTEGER, NUMY AS INTEGER, WORD AS STRING

Dim Soupixel As Bitmap, Soutop As INTEGER, SOULEFT AS INTEGER

Dim Soucolor As Long, SougetColor AS String, Numn As Integer

Dim TmpWord As String, Numdifred AS Integer, Numdifgreen As INTEGER, NUMDIFBLUE AS INTEGER

Dim Newred As Integer, NewGreen As Integer, Newblue AS Integer

ON Error ResMe next

Kill "C: /TEMP1.TXT"

Open "C: /TEMP1.TXT" for append as # 1 'transforms text into numbers and stores files

For Numx = 1 to len (txtsource.text)

NumTMP = ASC (MID (TXTSource.Text, Numx, 1))

chrtmp = format (NUMTMP)

If NumTMP> = 0 Then ChrtMP = " " & chrtmp

For numy = 1 to len (chrtmp)

Word = Format (ASC (MID (CHRTMP, NUMY, 1)))))

Print # 1, Word;

Next Numy

Next Numx

Close # 1

Open "C: /TEMP1.TXT" for Input AS # 2

GetObject Picsource.Picture.Handle, Len (SOUPIXEL), SOUPIXEL

Picobject.picture = Nothing: Picobject.cls

For Soutop = 0 to SOUPIXEL.BMHEIGHT - 1

For Souleft = 0 to SOUPIXEL.BMWIDTH - 1

'Remove the RGB value of each point

Soucolor = getpixel (picsource.hdc, souleft, soutop)

SougetColor = HEX (Soucolor)

Numn = 6 - len (SougetColor)

SougetColor = String (NUMN, "0") & SougetColor

'Take three numbers

IF not (EOF (2)) THEN

TmpWord = INPUT (3, # 2)

Numdifred = VAL (Left (TmpWord, 1))

Numdifgreen = VAL (MID (TmpWord, 2, 1))

Numdifblue = Val (Right (TmpWord, 1))

END IF

'Adding the number with the R value, g value, B value or subtract

NEWRED = HEXDEC (Right (SougetColor, 2)) - Numdifred

IF newred <0 Then newred = HEXDEC (Right (getColor, 2)) NumdifRednewgreen = HEXDEC (MID (SougetColor, 3, 2)) - Numdifgreen

IF newgreen <0 Then newGreen = HEXDEC (MID (SougetColor, 3, 2)) Numdifgreen

NEWBLUE = HEXDEC (LEFT (SougetColor, 2)) - Numdifblue

If newblue <0 Then newblue = hexdec (LEFT (SougetColor, 2)) Numdifblue

Numdifred = 0: Numdifgreen = 0: Numdifblue = 0

Doevents

'Form a target picture

Picobject.pset (Souleft, Soutop), RGB (Newred, NewGreen, Newblue)

Next souleft

Next Soutop

Close # 2

SavePicture Picobject.Image, "C: /Object.bmp"

Picobject.picture = loadingPicture ("c: /object.bmp")

End Sub

Private sub cmdpicturetotext_click ()

DIM Pixel as bitmap

Dim Soutop As INTEGER, SOULEFT AS INTEGER

DIM Soucolor As Long, Objcolor As String, ObjgetColor As String

Dim Soured As INTEGER, Sougreen As Integer, Soublue AS Integer

Dim objred as integer, objblue as integer, objblue as integer

Dim Soun As INTEGER, OBJN AS INTEGER

DIM Numdifred As Integer, Chrdifred As String

Dim Numdifgreen As Integer, Chrdifgreen As String

DIM Numdifblue As Integer, Chrdifblue As String

DIM DIFCERENCE AS STRING, NUMTMP AS INTEGER, CHRTMP AS STRING, TMPWORD AS STRING, WORD AS STRING

ON Error ResMe next

GetObject picsource.picture.handle, len (pixel), Pixel 'Get the pixel

Kill "C: /TEMP2.TXT" "If there is a" TEMP2.TXT "file, clear it

Open "C: /TEMP2.TXT" for append as # 3

For SOUTOP = 0 to Pixel.Bmheight - 1

For Souleft = 0 to Pixel.BmWidth - 1

'Get the RGB value of each point of the source

Soucolor = getpixel (picsource.hdc, souleft, soutop)

SougetColor = HEX (Soucolor)

Soun = 6 - len (SougetColor)

SougetColor = String (Soun, "0") & SougetColorsoured = HEXDEC (Right (SougetColor, 2)) 'Translate to Red, Green, Blue value

Sougreen = HEXDEC (MID (SougetColor, 3, 2))

Soublue = HEXDEC (LEFT (SougetColor, 2))

'Get the RGB value of each point

Objcolor = getpixel (Picobject.hdc, SouleFT, Soutop)

ObjgetColor = HEX (Objcolor)

Objn = 6 - len (ObjgetColor)

ObjgetColor = String (Objn, "0") & objgetColor

Objred = HEXDEC (Right (ObjgetColor, 2))

Objgreen = HEXDEC (MID (ObjgetColor, 3, 2))

ObjBlue = HEXDEC (Left (ObjgetColor, 2))

Numdifred = Soured - Objred 'deposits the difference into the file

chrdifred = format (numdifred)

If Numdifred <0 Then Chrdifred = Format (Objred - Soured)

Numdifgreen = Sougreen - Objgreen

Chrdifgreen = format (Numdifgreen)

If Numdifgreen <0 Then Chrdifgreen = Format (Objgreen - Sougreen)

Numdifblue = Soublue - Objblue

Chrdifblue = format (Numdifblue)

IF Numdifblue <0 Then Chrdifblue = Format (Objblue - Soublue)

Difference = chrdifred & chrdifgreen & chrdifblue

Print # 3, DIFCERENCE;

Next souleft

Next Soutop

Close # 3

Open "C: /TEMP2.TXT" for Input AS # 4 'From the file restore text

Do While Not Eof (4)

NumTMP = INPUT (2, # 4)

ChrtMP = CHR (Val (NumTMP))

IF (Len (TmpWord> 1) and (chrtmp = " " or chrtmp = "-") THEN

Word = CHR (Val (TmpWord))

TxtObject.text = txtObject.text & word

TmpWord = ""

END IF

TmpWord = TmpWord & Chrtmp

Loop

TXTOBJECT.TEXT = TxtObject.text & chr (Val (TmpWord))

Close # 4

End Sub

The above programs are debugged in VB6.0 in the Windows98 system.

In summary, this method has a modification of the RGB value of the picture to 0 to 9, which is difficult to distinguish between target pictures and source pictures, so it can be used for file encryption.

转载请注明原文地址:https://www.9cbs.com/read-94770.html

New Post(0)