Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Creating Transparent Bitmaps for NT 2000

Posted on 1999-07-16
21
Medium Priority
?
212 Views
Last Modified: 2013-12-03
I have source code in VB that will take in a bitmap, and write to the form file a transparent form of the bitmap.  The code is available at:
http://www.mvps.org/vbnet/code/bitmap/transparent.htm
I changed it so that I can open a bitmap while running the application, and then save (but this just saves the same image with a dif name for now - i want to change this later).  My question is that is there anyway you could look at the given code, and change it so that instead of saving right on the form, it would save the new .bmp onto a picture box?  Or better yet, just save the name of the new transparent bitmap in a string data type.  This way I can save it to a directory.

Also, is there anyway that instead of opening each file one at a time, could I open the directory and have the application list through all the bitmaps in the direcotry, running this program on them.  Note, there are not only bitmaps in this directory, so if that was possible, I'd have to have a conditional "if" statement somewhere to check if it has a .bmp extension.  Any help?  Thanks
0
Comment
Question by:peterma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 5
  • +1
21 Comments
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1525354
Too many question. You have to program it yourself.

Hint?
    savepicture picture1, "Mybitmap.bmp"

0
 
LVL 10

Accepted Solution

by:
viktornet earned 400 total points
ID: 1525355
use the following code instead when you click on the button....

Private Sub Command1_Click()

  Dim R As RECT

  With R
   .Left = 0
   .Top = 0
   .Right = Picture1.ScaleWidth
   .Bottom = Picture1.ScaleHeight
  End With

  TransparentBlt Picture1.hdc, Picture1.hdc, Picture1.hdc, R, 20, 20, vbWhite

End Sub

that;s all,,,, if you want to save that image into a file, then use the following code right after the call to TransparentBlt() function...

SavePicture Picture1, "TransBmp.bmp"

If you want your other question to be answered about the directory and going through all the BMPs, you should ask a different question and it will be answered after that... you're not allowed to ask more than one question per thread....

Good Luck!!

..-=ViKtOr=-..
0
 
LVL 5

Expert Comment

by:KDivad
ID: 1525356
Peterma may have asked two questions per thread, but he/she did post more points than either by itself was worth. Ya'll ought to be glad for that, since a LOT of people are posting not enough points. Sorry if this goes against the grain, but I can't in good conscience let so many points go for a single simple answer.

Peterma, one of the simplest ways to get all .bmp's from a directory is to use a filelist box. In code, use something like this:

File1.Path = PathToYourBMPFiles
File1.Pattern = "*.bmp"
If File1.ListCount > 0 Then
    For I = 0 to File1.ListCount - 1
        'Insert code to do whatever to the files.
        'You could open the .bmp in a picturebox here,
        'use Viktornet's code to alter the pic, then
        'use the code to resave the file.
    Next
End If


Again, I apologize to those experts greedy enough to take a hard question's worth of points for an easy question.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Expert Comment

by:KDivad
ID: 1525357
I forgot one thing:

Peterma, they are right. You should only ask one question per thread. This gives experts who know the answer to one and not the other the chance to give a good answer to one without getting points for both.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1525358
KDivad, u talkin to me? I didn't say that all da ptz should go for that.,, s/he can decrease it to 100 or whatever.... here is the problem with asking more thatn a single question on the same thread...

1) Sometimes people know the answer to only one of the questions... they can answer that, but then the person rejects the answer.// that means that probably one of the more knowledgable experts should answer the question 'cuz they know the answers to both questions.... i dont think that's too convenient....

2) People like me (too damn lazy) answer only the question that'd take a minute or so to solve... since I aint got time as I did a few months back now i'm tryin to solve only the easy problems and the first question on this thread was one of those.... but as usually the guy wants to get both questions, which i'm too lazy to supply code for... welll, the code for traversing folders and stuff is easy too, but i didnt feel like writing so i didn't answer that...

3) thoze r E-E's rulez....

>>greedy enough
awww.... shuddap....

-vik-
0
 

Author Comment

by:peterma
ID: 1525359
OK, thanks for letting me know about the 2 question thing.  There is nothing i can do now is there?  unless i get some points back, I can't post another question.  I have only 70 pts left.

Anyways, in regards to saving this transparent image to file, it doesn't work.  I actually have two picture boxes on my form at once.  I want the trasparent one to go to the other picture box.  I changed your suggested code to:
  End With

  TransparentBlt Picture2.hdc, Picture2.hdc, Picture1.hdc, R, 20, 20, &HC0C0C0

But that puts the bitmap in the second picture box, but it's not alligned correctly.  Also, when I try to write:

    SavePicture Picture2.Picture, aFileNameTemp + ".bmp"

I get the error the run time error 380 - imvalid property value.  But the image is in the 2nd picture box, but like I said it's sort of misalligned.  Not up in the corner like the first picture box.  If I change it to what you had, both places as "Picture1" instead of "Picture2" I get the original saved image again.  When I make the image transparent, It keeps the original in the upper corner, then puts the transparent one below and to the left of the original, but in the same picture box (Picture1).  Is there any way to get around this?  

Also, is there a way to get some points back to ask the other question seperately?  Thanks.

Pete
0
 

Author Comment

by:peterma
ID: 1525360
KDavid
I asked the other question separately now worth 70 pts.  If you could help me with that one it would be great.  I tried doing what you said, but I get the error:

run time error 424:
Object required

this occurs when I have:

File1.Path = "C:\filelib"

any help?  Thanks

Pete
0
 
LVL 5

Expert Comment

by:KDivad
ID: 1525361
I'll do it for free, I shouldn't have stuck my nose up like I did. My code requires a filelist box, that's the only thing I can think of that might be wrong. The only way to get points back is to have a question deleted.
0
 
LVL 5

Expert Comment

by:KDivad
ID: 1525362
I can make a guess about the alignment, but it's really only a guess. Are the parameters "20" and "20" perhaps coordinates? To align it to the upper left corner, maybe you need zero's instead of 20's?
0
 

Author Comment

by:peterma
ID: 1525363
you know what, i don't think this is going to work.  I don't think bitmaps can be made transparent.  That's what icons are used for.  They are really two bitmaps, one being the transparent feature.  I think all this code does is fill in the specified color of the bitmap with the color of the picturebox, or form that its being rewritten to.  Therefore it looks transparent, but it isn't. You can't capture the image in any way.  I think that's what's going on and therefore it can't be done...creating a transparent bitmap that is.  any thoughts?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1525364
peterma, when you look at the screen beofre posting a comment it gonna show you a number in an editbox that says 200... just change that to 100 for a single question... that will refund 100 points to your account...
0
 
LVL 5

Expert Comment

by:KDivad
ID: 1525365
I thought you couldn't decrease points to keep people from decreasing right before accepting an answer.
0
 

Author Comment

by:peterma
ID: 1525366
We'll see what happens, I tried it now...
Did it work?
0
 

Author Comment

by:peterma
ID: 1525367
No, I guess you can't decrease points, only increase them.  Nice try though.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1525368
why don't you just reject and get over with this..Ask Linda to refund yours points :)
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1525369
Reject viktornet answer and I'll give you the right one.
0
 

Author Comment

by:peterma
ID: 1525370
who the hell is linda?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1525371
Nope, if Mirky's gonna answer then don't reject :) I'd better give you the correct answers myself :))

peterma, if you want me to give you the answers to both questions just say so and I will take the time to make an example for you, and even send it to you over the mail.... if you do please let me know what your e-mail address is :)
0
 

Author Comment

by:peterma
ID: 1525372
I would love the correct answer, the only thing is that I don't think there is one.  I can't use this towards my project because it really isn't making the bitmap transparent, just filling in one color with another to make it look transparent.  I can't capture the bitmap and I can't use it with my c++ code.  So there isn't a correct answer.  I have to figure out how to hard code it into my c++ code I have.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1525373
hint: bitmap does not support transparent but jpg does...
0
 

Author Comment

by:peterma
ID: 1525374
i know, and so do icons, but i need bitmaps because that's what all our images are...and i'm just going to rewrite some of the code to support that.  thanks anyways
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
Suggested Courses

721 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