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

Creating Transparent Bitmaps for NT 2000

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
peterma
Asked:
peterma
  • 8
  • 5
  • 5
  • +1
1 Solution
 
MirkwoodCommented:
Too many question. You have to program it yourself.

Hint?
    savepicture picture1, "Mybitmap.bmp"

0
 
viktornetCommented:
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
 
KDivadCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
KDivadCommented:
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
 
viktornetCommented:
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
 
petermaAuthor Commented:
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
 
petermaAuthor Commented:
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
 
KDivadCommented:
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
 
KDivadCommented:
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
 
petermaAuthor Commented:
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
 
viktornetCommented:
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
 
KDivadCommented:
I thought you couldn't decrease points to keep people from decreasing right before accepting an answer.
0
 
petermaAuthor Commented:
We'll see what happens, I tried it now...
Did it work?
0
 
petermaAuthor Commented:
No, I guess you can't decrease points, only increase them.  Nice try though.
0
 
viktornetCommented:
why don't you just reject and get over with this..Ask Linda to refund yours points :)
0
 
MirkwoodCommented:
Reject viktornet answer and I'll give you the right one.
0
 
petermaAuthor Commented:
who the hell is linda?
0
 
viktornetCommented:
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
 
petermaAuthor Commented:
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
 
MirkwoodCommented:
hint: bitmap does not support transparent but jpg does...
0
 
petermaAuthor Commented:
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 8
  • 5
  • 5
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now