Solved

GGGGGRRRRRR Bitmap help please

Posted on 2003-11-30
10
235 Views
Last Modified: 2010-05-01
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
Comment
Question by:OptionsMM
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 5

Expert Comment

by:sanjaykashyap19
ID: 9847213
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
 

Author Comment

by:OptionsMM
ID: 9847240
This picture is not embedded in a form.  How do I adjust it withou having a .hDC reference to something in a form?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9848155
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
 

Author Comment

by:OptionsMM
ID: 9848173
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9848227
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 17

Expert Comment

by:zzzzzooc
ID: 9849898
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
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 9849906
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
 

Author Comment

by:OptionsMM
ID: 9853026
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 9853439
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
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 9853490
Here is a control you could try:

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

Idle_Mind
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now