Closed Thread
Results 1 to 11 of 11

Bitmap manipulation from VBA/VB

  1. #1
    John Keith
    Guest

    Bitmap manipulation from VBA/VB

    I am needing to load a bitmap, then run through some code that would
    transform the image by looking at each pixel's color and if the RGB is less
    than 10,10,10 then change the pixel to some other color. How do I do this?
    Is there some kind of object I can use that will allow changing this from
    VB/VBA?

    --
    Regards,
    John

  2. #2
    K Dales
    Guest

    RE: Bitmap manipulation from VBA/VB

    You can do this if you use Windows API functions; here is a reference for the
    Bitmap functions (note in particular GetBitmapDimensionEx and
    GetPixel/SetPixel):
    http://msdn.microsoft.com/library/de...tmaps_87eb.asp
    If you are not familiar with using API library functions you may want to
    search the MSDN libarary on the topic.
    --
    - K Dales


    "John Keith" wrote:

    > I am needing to load a bitmap, then run through some code that would
    > transform the image by looking at each pixel's color and if the RGB is less
    > than 10,10,10 then change the pixel to some other color. How do I do this?
    > Is there some kind of object I can use that will allow changing this from
    > VB/VBA?
    >
    > --
    > Regards,
    > John


  3. #3
    John Keith
    Guest

    RE: Bitmap manipulation from VBA/VB

    I followed the link for the API calls. I found some more info on how to use
    API from VBA (see link below). I am still confused on how the API calls will
    relate to the VBA code......
    ActiveSheet.Pictures.Insert( _
    "C:\Documents and Settings\JKeith\My Documents\My Pictures\test.bmp" _
    ).Select
    Selection.ShapeRange.IncrementLeft 108
    Selection.ShapeRange.IncrementTop 91.5
    Selection.ShapeRange.IncrementRotation 60
    Selection.ShapeRange.ScaleHeight 0.65, msoFalse, msoScaleFromTopLeft
    Selection.ShapeRange.ScaleWidth 0.65, msoFalse, msoScaleFromTopLeft

    Do the API calls for SetPixel directly change the BMP file? (so I would do
    all the API calls before I "insert" the picture into the spreadsheet?)

    Is there some way to assign the API picture handle to the pictures.insert?
    or will this have to be done externally?

    For anyone that is looking to find out how to call API from VBA.... (this
    link is for you)
    http://www.awprofessional.com/articl...?p=366892&rl=1

    --
    Regards,
    John


    "K Dales" wrote:

    > You can do this if you use Windows API functions; here is a reference for the
    > Bitmap functions (note in particular GetBitmapDimensionEx and
    > GetPixel/SetPixel):
    > http://msdn.microsoft.com/library/de...tmaps_87eb.asp
    > If you are not familiar with using API library functions you may want to
    > search the MSDN libarary on the topic.
    > --
    > - K Dales
    >
    >
    > "John Keith" wrote:
    >
    > > I am needing to load a bitmap, then run through some code that would
    > > transform the image by looking at each pixel's color and if the RGB is less
    > > than 10,10,10 then change the pixel to some other color. How do I do this?
    > > Is there some kind of object I can use that will allow changing this from
    > > VB/VBA?
    > >
    > > --
    > > Regards,
    > > John


  4. #4
    Registered User
    Join Date
    01-07-2012
    Location
    Canberra, Australia
    MS-Off Ver
    Office 2003
    Posts
    6

    Re: Bitmap manipulation from VBA/VB

    For an unrefined but effective solution, see http://zababcdblog.blogspot.com/2012...excel-vba.html and the improvement at http://zababcdblog.blogspot.com/2012...cel-vba-2.html

  5. #5
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: Bitmap manipulation from VBA/VB

    Zababcd, this question is from 2005. I doubt that the asker will return to see your comment. The only purpose your post serves is an attempt to improve your blog's SEO.

    If you want to provide solutions, in this forum, please feel welcome to do so. But please stick to current issues, summarize the essence of the suggestion in the post, and don't just post blind links.

    regards,

  6. #6
    Registered User
    Join Date
    01-07-2012
    Location
    Canberra, Australia
    MS-Off Ver
    Office 2003
    Posts
    6

    Re: Bitmap manipulation from VBA/VB

    In my defence, my goal was to share my solution, not for 'my blog's SEO' but because I didn't see my solution when I was looking for it, so I thought I would provide it for anyone else who was looking for it. I searched for people with this problem and provided my solution for them. I failed to check when the question was asked, and will do so in any future posts.

  7. #7
    Registered User
    Join Date
    03-02-2012
    Location
    British Columbia, Canada
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Bitmap manipulation from VBA/VB

    I just wanted to put in a humble request to teylyn - hopefully I'm not overstepping bounds! Zababcd's post was very helpful to me, and I personally appreciate that (he?) updated the thread. I just wanted to let you both know that it was helpful (thanks Zab), and wonder if instead posts like this could be accepted... unless the poster can be re-directed to a more recent version of the question. I'm in agreement with Zababcd's philosophy, the idea that a thread is closed once a solution is found, and hope teylyn will reconsider your position.

  8. #8
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,612

    Re: Bitmap manipulation from VBA/VB

    this thread should be closed now!
    Ben Van Johnson

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Bitmap manipulation from VBA/VB

    Hello pure_designer,

    Welcome to the Forum!

    There is a policy in place here at the forum so members can share their thoughts and solutions about older posts. If you find an older post that is relevant to a problem you have then start a new thread and include a link to that thread in your post. Please take some time to read through the forum's rules on posting as this situation and others are covered in detail.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  10. #10
    Registered User
    Join Date
    06-23-2017
    Location
    USA
    MS-Off Ver
    various
    Posts
    15

    Re: Bitmap manipulation from VBA/VB

    Leith Ross said, "There is a policy in place here at the forum so members can share their thoughts and solutions about older posts."

    I registered partly to say that I like this policy, and often find use from replies that are several years after the original post. I appreciate when someone does add a new solution to an old problem. It is especially useful for a program like Excel which evolves over time, as does the operating system, and what people use it for.

    The Zababcd blog is gone, so those links don't work. Part of the code can be found at another forum.

    The idea is to load an image into an array, and then use the array data to create an image.

    I found some other interesting takes on this. Daniel Pineault discusses resizing an image in VBA using the Microsoft Windows Image Acquisition (WIA) interface and also using using FreeImage. The latter does include some source code that he charges for, but FreeImage (of course) is free.

    FreeImage is a great lead, since it includes wrapper modules that work with almost anything.

    It says it can "directly access bitmap bits and palette."

    "Functions are provided which allow you to directly access the bitmap palette (if available) and bitmap bits."

    The wrappers work with Visual Basic as well as with any Component Object Model (COM) aware development environment (which includes VBA). It would be nice if it included VBA source code, but this is the next best thing.

    For that matter, other tools that can talk to COM would work. I've used AutoHotkey to talk to the Excel COM. Something like that might be hackish, but if you had to, you could use an outside tool to take a graphic from Excel, manipulate it, and then send it back in.

    There is also a library of games written for Excel. No doubt some of them use innovative ways to manipulate graphics.

    And finally, don't forget that you can draw lines and shapes even onto say a userform. That might be of use for some types of graphic manipulation.

    Anyway, these Excel resources on the web are very useful and there is a lot of good help available. So thank you for your contributions!

    Dan

  11. #11
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Bitmap manipulation from VBA/VB

    Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1