Results 1 to 21 of 21

Thread: creating an image component. merging images.

  1. #1

    Thread Starter
    Lively Member Silverbug's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    71

    Question creating an image component. merging images.

    Hi all,

    Im in the process of creating an image component for use on an asp server. What I wanted to know if what is the best way to load two files and then merge them together, ie i load a canvas (what should i use for the canvas) and then load one file and "paste" it onto the canvas, then load a second file and "paste" that one onto it.

    Thing is im not really sure on what to use for the canvas, ie picturebox or image, and about the pasting of the second images to it. (i assume you use bitblit or something like that)

    Any way any help would be appreciated, i have searched around a bit for some other posts on similar stuff to this but couldnt really work out what the best way of doing this was.
    Silverbug,
    This space intentionally has nothing but text explaining why this
    space has nothing but text explaining that this space would otherwise
    have been left blank, and would otherwise have been left blank.

  2. #2
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    I dont know if this is what you are after, but heres a program i made some time ago....
    Attached Files Attached Files
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  3. #3
    Frenzied Member cyborg's Avatar
    Join Date
    May 2000
    Location
    Sweden
    Posts
    1,755
    there is a faster way to do this with api....
    dont remember how right now....think its called AlphaBlend
    you can check it out on www.allapi.net
    Check out the FAQ and do a search before you post.
    My tutorials: Anti-Alias Pixels, Accurate Game Loop, Resource File

  4. #4

    Thread Starter
    Lively Member Silverbug's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    71
    hmm, i dont really want to blend the two pictures, more paste one on the canvas and then paste the next picture somewhere else on the canvas (which could include over the top of the first picture)
    Silverbug,
    This space intentionally has nothing but text explaining why this
    space has nothing but text explaining that this space would otherwise
    have been left blank, and would otherwise have been left blank.

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Using a Picturebox for the canvas and the BitBlt API should cover all of your bases. Look up the BitBlt API over at allapi.net. After you've gained a solid understanding, you'll need to realise a few things to get it to work.

    1. If anything (source or destination) is going to be invisible during the BitBlt call, it must have it's AutoRedraw property set to true (Picturebox).
    2. If AutoRedraw is set to true on the destination, issuing a .Refresh on the destination picturebox will make its contents visible once more.

    If you can't seem to get your head around it, I can get myself out of Linux and write you up an example.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  6. #6

    Thread Starter
    Lively Member Silverbug's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    71
    Ill take a crack at it and if I get stuck I'll let you know, thanks for the help.
    Silverbug,
    This space intentionally has nothing but text explaining why this
    space has nothing but text explaining that this space would otherwise
    have been left blank, and would otherwise have been left blank.

  7. #7

    Thread Starter
    Lively Member Silverbug's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    71
    ok i know its probably something stupid but i keep getting a object variable or with block variable not set error whenever i try and use a picture box. i cant work out what ive done wrong

    Dim Canvas As PictureBox

    .....

    Canvas.Width = strtemp
    Canvas.Height = 9

    The error occures on the line canvas.width....
    Silverbug,
    This space intentionally has nothing but text explaining why this
    space has nothing but text explaining that this space would otherwise
    have been left blank, and would otherwise have been left blank.

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I'm not sure what you're trying to do here - are you assigning a string to the numeric width? If so, that obviously will not work.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  9. #9

    Thread Starter
    Lively Member Silverbug's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    71
    um no, bit of an undescriptive variable name but its an integer

    basically when ever i try an access anything in any of my picture box variables they bring up the error.

    to put things in perepective, im creating an asp component which will be used to create an image that is made up of x number of smaller image. its for a page counter.
    Last edited by Silverbug; Dec 16th, 2002 at 12:49 AM.
    Silverbug,
    This space intentionally has nothing but text explaining why this
    space has nothing but text explaining that this space would otherwise
    have been left blank, and would otherwise have been left blank.

  10. #10
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Yikes. This'll be a bit harder. I'm off to bed now, but tomorrow, I can show you how to "dive deep" into the GDI32 API... Wow I sound stupid, huh? Anyway, I'll show you about device contexts, how to make offscreen device contexts (a device context is simply a pointer to a graphical area), and how to merge images, etc. All using the API...

    But it's late. If you want, you can look up all of those things yourself (bitblt, offscreen dcs, etc.) and try to make them fit... I dunno if I'm making any sense, I'm too tired!

    So, g'night.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  11. #11

    Thread Starter
    Lively Member Silverbug's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    71
    Yeah that would be cool. If anyone knows of any examples on this sorta stuff that would be cool. Kinda disapointed in whats happend to vbworld's site, was good unitll they merged
    Silverbug,
    This space intentionally has nothing but text explaining why this
    space has nothing but text explaining that this space would otherwise
    have been left blank, and would otherwise have been left blank.

  12. #12

    Thread Starter
    Lively Member Silverbug's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    71
    Merry Chirstmas and happy new year to all .

    Im still no closer to solving this damn problem, would be great if i could get some examples on how i can solve this (see 2-3 posts up) or if someone can explain how to join two pictures together and save the result, all in memory seeing as this is going to be an asp component.
    Silverbug,
    This space intentionally has nothing but text explaining why this
    space has nothing but text explaining that this space would otherwise
    have been left blank, and would otherwise have been left blank.

  13. #13
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Okay. I wasn't able to respond before but I can now. Here's what I was going to tell you:
    VB Code:
    1. '// How to use BitBlt
    2. Dim RC '// RC stands for Return Code.
    3. '// Usually it doesn't matter (we can just throw it away), but it's useful if it doesn't work!
    4.  
    5. '// Prototype
    6. '// RC = BitBlt([i]Destination[/i], [i]X Value (horizontal)[/i], [i]Y Value (vertical)[/i], [i]Width[/i], [i]Height[/i], [i]Source[/i], [i]X Value of Source (where to start getting data from horizontally), [i]Y Value of Source (where to start getting data from vertically)[/i], [i]How to Copy[/i])
    7.  
    8. '// Source and Destination are found by using the .hDC properties of pictureboxes, or just by offscreen device contexts (that's what DC stands for, the h stands for a handle, so it's a handle to a device context).
    9.  
    10. '// All Width, Y, X, etc. properties are in PIXELS. Remember to set your picturebox's ScaleMode property to 3 (pixels).
    11.  
    12. '// How to Copy: There are pre-defined constants starting with VB5 (I think) for the copy modes: SrcCopy (copy source bits to destination), SrcAnd (AND source bits with destination), SrcPaint, etc. SrcCopy is used for normal blits, SrcAnd/SrcPaint/MergePaint are used for transparent blitting (eg. mask is used to determine transparency).
    13.  
    14. '// Now, let's use this:
    15.  
    16. RC = BitBlt(PicOut.hDC, 0, 0, 200, 200, PicIn(0).hDC, 0, 0, vbSrcCopy)
    17.  
    18. '// This copies PicIn(0) onto PicOut at (0, 0) with a width and height of both 200 (you can also use PicIn(0).ScaleWidth, PicIn(0).ScaleHeight, etc.). It also uses the COPY constant to make the bits there equal the bits on the source (ex. no transformation).
    19.  
    20. '// You can also use AutoRedraw = True on all of the pictureboxes, and make them invisible.
    21.  
    22. With PicOut
    23.     .AutoRedraw = True
    24.     .Visible = False
    25. End With
    26.  
    27. With PicIn(0)
    28.     .AutoRedraw = True
    29.     .Visible = False
    30. End With
    31.  
    32. RC = BitBlt(PicOut.hDC, 0, 0, 200, 200, PicIn(0).hDC, 0, 0, vbSrcCopy)
    33.  
    34. [b]PicOut.Refresh[/b]
    35.  
    36. '// You must use ***.Refresh to actually update the screen with the new picture. This allows games that use BitBlt (or other GDI calls) to wait until a monitor sync to draw, and also to make flicker-free drawing. If you didn't have autoredraw, you'd see the screen clearing and everything being drawn. With this you can make it show only when everything's already drawn.
    Next post I'll show how to use OffScreen DCs! Make sure to use the API Viewer to get the BitBlt API Declaration, as well.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  14. #14
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    VB Code:
    1. '// How to use DCs
    2. '// A DC (put very simply) is a reference to where in memory a picture is stored. Generally, to make a DC, you can do the following:
    3.  
    4. Dim lngDC '// Handle to newly created device context
    5. Dim lngOldBitmap '// Handle to old image, needed to prevent memory leaks
    6. Dim lngBitmap '// Handle to bitmap with newly loaded image
    7. Dim lngDesk '// Handle to desktop's DC
    8. Dim strImagePath '// Path to image you want loaded
    9.  
    10. '// Get Desktop's DC (we need to make this one compatible with the screen [ex. same colour depth])
    11. lngDesk = GetDC(GetDesktopWindow)
    12.  
    13. '// Create a new DC compatible with the desktop's
    14. lngDC = CreateCompatibleDC(DeskDC)
    15.  
    16. '// Load the image
    17. lngBitmap = LoadImage(App.hInstance, strImagePath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
    18.  
    19. '// Put it into the Device Context
    20. lngOldBitmap = SelectObject(lngDC, lngBitmap)
    21.  
    22. '// Let other apps use the desktop's DC
    23. Call ReleaseDC(lngDesk, GetDesktopWindow)
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  15. #15

    Thread Starter
    Lively Member Silverbug's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    71
    Hey great, thanks heaps for that... now how does it all tie together? (dont say string )
    as in do i need to use DC's seeing as this is going to be an asp component?
    Silverbug,
    This space intentionally has nothing but text explaining why this
    space has nothing but text explaining that this space would otherwise
    have been left blank, and would otherwise have been left blank.

  16. #16
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Here's what you might do. After you get the user's input (say, two files that are uploaded), run the component. It loads the two images in the same directory (image1.bmp and image2.bmp), and outputs image3.bmp. You create two DCs and load image1 and image2. Then you create a 3rd DC, use BitBlt to transfer both images on. Then, save this 3rd DC to a file (this is the only part I'm unsure of). You can be crafty and use this module called "freeimage" which can save to a variety of formats (png, jpg, gif, tiff, etc.)


    I just forget where I got it from!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  17. #17

    Thread Starter
    Lively Member Silverbug's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    71
    Ok im not quite sure on these dc thingys. (if you know of any good tuts on them its might save you explaining to me, ive had a search but cant find much on the topic)

    One question tho, you say i should create three dc's (which i understand) and your example gets the dc of the desktop, does it have to be a dc of the desktop? and would that be the desktop of the client computer(browser) or of the server?

    hmm in regards to saving i didnt really want to have to load more than one dll onto the server, (however if thats gona be a problem i guess thats all i can do) seeing as i dont own/admin the server, and am going to have to convince my hosting company to install it hehe

    btw thanks for all your help on this.
    Silverbug,
    This space intentionally has nothing but text explaining why this
    space has nothing but text explaining that this space would otherwise
    have been left blank, and would otherwise have been left blank.

  18. #18
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Well, once you run that DC function, you've got the DC (lngDC) that holds the image. If you aren't very graphics-minded, you can simply think of it as an image. Plain as that.

    We load the desktop DC because it's guaranteed to be there. We need to set the DC's memory to be in the same format as the computer is currently using (pixel format [like bit depth], DPI, etc).

    And finally, that would be of the server (because that's where the component runs). And, this can be only 1 DLL.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  19. #19

    Thread Starter
    Lively Member Silverbug's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    71
    Hey I havent had much time to look at this (heaps of work atm ) but now that ive come back to it, i get errors. It cant find the GetDC function in the DC code.
    Silverbug,
    This space intentionally has nothing but text explaining why this
    space has nothing but text explaining that this space would otherwise
    have been left blank, and would otherwise have been left blank.

  20. #20
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    GetDC is a Win32 API call!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  21. #21

    Thread Starter
    Lively Member Silverbug's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    71
    hmmmmm, I think I have just found what im looking for. This is all done in asp code (no component required!) Including saving the file in gif format.

    http://users.bigpond.net.au/mrjolly/

    (go to aspcanvas)
    Last edited by Silverbug; Jan 12th, 2003 at 05:17 PM.
    Silverbug,
    This space intentionally has nothing but text explaining why this
    space has nothing but text explaining that this space would otherwise
    have been left blank, and would otherwise have been left blank.

Posting Permissions

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



Click Here to Expand Forum to Full Width