• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 388
  • Last Modified:

Color Depth and Sent Bitmap to array (Picture Box)

Dear Expert
 I Need to Decrease Color depth of Picture in pictureBox (240*128) to black & white color and sent to array in memory.
Pls Help me.
this very urgent.....
0
knun
Asked:
knun
  • 4
  • 3
1 Solution
 
knunAuthor Commented:
For more information
I have Picture in Picturebox already i just need to change to black and white color depth (1 bit) , and after change to 1 bit depth sent this picture (240*128 Pixel) to array .
for read data inside and sent to LCD by my module.
0
 
rettiseertCommented:
This is a very simple way to do it: paste a picture box in a form, load a 240 * 128 pixels image on it and run this code:

Option Explicit

Private Sub Command1_Click()

    Dim x As Long, y As Long
    Dim Clr As Long
    Dim Pixels(0 To 239, 0 To 127) As Boolean

    Picture1.ScaleMode = vbPixels
   
    For x = 0 To 240 - 1
        For y = 0 To 128 - 1
            Clr = Picture1.Point(x, y)
            Clr = To1Bit(Clr)
            Picture1.PSet (x, y), Clr
            Pixels(x, y) = IIf(Clr = vbWhite, True, False)
        Next
    Next
   
End Sub

Private Function To1Bit(Clr As Long) as Long

    Dim r As Long, g As Long, b As Long
   
    Const HARDNESS = 150
   
    'Debug.Print Hex(Clr)
    r = (Clr And &HFF0000) / 2 ^ 16
    g = (Clr And &HFF00&) / 2 ^ 8
    b = (Clr And &HFF&)
   
    To1Bit = IIf((r + g + b) / 3 > HARDNESS, vbWhite, vbBlack)
   
End Function
0
 
knunAuthor Commented:
Very Thank rettiseert.
i will accept your answer but another question ^_^ do you know how to resize image to 240*128 ^_^
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rettiseertCommented:
   Dim FileName As String
   
    FileName = "C:\1.jpg"  '<---- This is the file you want to show in a 240*128 picture box
   
    Picture1.AutoRedraw = True
   
    Picture1.PaintPicture LoadPicture(FileName), 0, 0, Me.ScaleX(240, vbPixels, Me.ScaleMode), Me.ScaleX(128, vbPixels, Me.ScaleMode)
0
 
knunAuthor Commented:

thank rettiseert ,  but i don't want to operate image to file (Harddisk) just play with it in memory
0
 
rettiseertCommented:
ok, in that case you can load your picture at design time in a hidden picturebox and then, in your visible picturebox use something like:

  Picture1.AutoRedraw = True
   
    Picture1.PaintPicture HiddenPictureBox.Picture, 0, 0, Me.ScaleX(240, vbPixels, Me.ScaleMode), Me.ScaleX(128, vbPixels, Me.ScaleMode)
0
 
knunAuthor Commented:
Very thank rettiseert.
you help me so much.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now