Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 245
  • Last Modified:

GGGGGRRRRRR Bitmap help please

I am trying to edit a bitmap image from Microsoft Access.  This code does not work

Sub SavePic()

    Dim Pic As New StdPicture
    Dim A As Long
    Dim B As Long

    Set Pic = LoadPicture("C:\Dot.bmp")
    A = SetPixel(Pic.hdc, 0, 0, RGB(255, 0, 0))
   
    SavePicture Pic, "C:\Dot.bmp"
    MsgBox A
   
End Sub

msgbox A always returns -1 and i cant figure out what "hdc" is or how to get this done.

500 points to the one who can fix this fast.


0
OptionsMM
Asked:
OptionsMM
  • 4
  • 3
  • 2
  • +1
1 Solution
 
sanjaykashyap19Commented:
I not have idea about Access
If AutoRedraw property is there then set the
Pic.AutoRedraw = True

look

http://oldlook.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20698681.html


Following code working fine in VB

' Randomly color all the pixels in window Form1.  This example
' gets the rectangle of Form1 and iterates through all the points
' (pixels) inside of it.
Dim winrect As RECT  ' rectangle of window Form1
Dim rgbval As Long  ' RGB value of the randomly selected color
Dim x As Long, y As Long  ' counters for x and y coordinates
Dim retval As Long  ' return value

' Get the rectangle of window Form1.
retval = GetWindowRect(Form1.hWnd, winrect)

' Loop through each pixel within Form1.
For y = 0 To winrect.bottom - winrect.top
  For x = 0 To winrect.right - winrect.left
    ' Select a random color by choosing a value between 0 and 255
    ' inclusive for each component of the color.
    rgbval = RGB(Int(256 * Rnd), Int(256 * Rnd), Int(256 * Rnd))
    ' Set the pixel to the color above.
    retval = SetPixel(Form1.hDC, x, y, rgbval)
  Next x
Next y

0
 
OptionsMMAuthor Commented:
This picture is not embedded in a form.  How do I adjust it withou having a .hDC reference to something in a form?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
OptionsMM,

hDC stands for "Handle to Device Context".  You can only have a Device Context when you have a graphics object associated with some kind of device, such as the screen or printer.

As far as I know, you cannot manipulate an image without having it associated with some kind of control, be it either a form, picturebox or image control.  The control need not be visible though.

The StdPicture object gives you a way to store references to images in memory and easily switch the image referenced by a Device Context to a different one.

Regards,

Idle_Mind
0
Industry Leaders: 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!

 
OptionsMMAuthor Commented:
Okay- now we are getting somewhere.

Lets say I wanted to write a piece of code to create a new bitmap with 2 pixels to do the following

set 0, 0 to vbred
set 0, 1 to vb blue

and the save it to the C drive as "Dot".

If I could get this code I would be set :)

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You would do it basically as you have.  Add a PictureBox, "Picture1",  to your Form.

There are two versions of the code below.  

The first version will modify the two pixels in an existing image and overwrite it.

The second version will create a new image with just the two pixels.

Regards,

Idle_Mind

Sub SavePic() ' Modify an existing image "C:\Dot.bmp"
    Dim A As Long
    Dim B As Long

    Set Picture1.Picture = LoadPicture("C:\Dot.bmp")
    A = SetPixel(Picture1.hdc, 0, 0, RGB(255, 0, 0))
    B = SetPixel(Picture1.hdc, 0, 1, RGB(0, 0, 255))

    Set Picture1.Picture = Picture1.Image
    SavePicture Picture1.Picture, "C:\Dot.bmp"    
End Sub

Sub SavePic() ' Create a new image "C:\Dot.bmp"
    Dim A As Long
    Dim B As Long

    Me.ScaleMode = vbPixels
    Picture1.Width = 1
    Picture1.Height = 2
   
    A = SetPixel(Picture1.hDC, 0, 0, RGB(255, 0, 0))
    B = SetPixel(Picture1.hDC, 0, 1, RGB(0, 0, 255))

    Set Picture1.Picture = Picture1.Image
    SavePicture Picture1.Picture, App.Path & "\Dot.bmp"
End Sub
0
 
zzzzzoocCommented:
It'll be alot faster keeping your image in memory for modifying the bitmap data than just using SetPixel on a device context. If you aren't going to modify alot, go with Idle's choice. If you are, invest time to increase performance alot. Would write an example for what you want but might not be required since there are alot of examples of it already

"How to use Direct Memory Access to do Graphics"
http://www.visualbasicforum.com/t25347.html


If you need further help on the above example just ask and i'll come up with my own.
0
 
zzzzzoocCommented:
As a side not, i'm foggy in the area of you saying you're using MS Access, so if you have strict limitations with using certain Win32 API or general memory, then do say so.
0
 
OptionsMMAuthor Commented:
Yeah it isnt working.  

I cant seem to get the .hdc to work

I am using an "Image", and trying it with an OLEUnbound.  still i cant seem to get the .mdc property to work

is this the same as a Picturebox in VB?
is there a reference i need to add in?

Sub SavePic()

    Dim Image As Image
    Dim A As Long
    Dim B As Long
     
    Set Image = Forms!Main.Image
    Image.Picture = "C:\Clean.bmp"
    MsgBox Image.hdc
   
End Sub
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Hmm....seems the intrinsic controls in Access do not expose a Device Context...and a VB PictureBox is not the same as an Access Image Control.

I have seen some posts on how to get a PictureBox into Access and the short answer is you don't want to go there.
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20508015.html?query=ms+access+picturebox+hdc&searchType=topic

Trying to find how to get an hDC for an Access Image Control...

Idle_Mind
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here is a control you could try:

http://www.lebans.com/imageclass.htm

Idle_Mind
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

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