Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

jpg or bmp with asm

[color=Black][b]hello my friends.
i learn assembly, i watching lessons but i dont know how can i do show display one jpeg file or bmp file?
which file i must convert? i dont know?(dat. or bin. or other?)
and which converter?
can you help?
all thanks.[/b][/color]

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : [color=Black][b]hello my friends.
    : i learn assembly, i watching lessons but i dont know how can i do
    : show display one jpeg file or bmp file?
    : which file i must convert? i dont know?(dat. or bin. or other?)
    : and which converter?
    : can you help?
    : all thanks.[/b][/color]
    :

    Which OS are you developing for?
    Or do you have an io library with your assembly package?

    There is no native assembly way to do this - it depends totally on the OS.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • di.di. Member Posts: 2
    for windows
    x86
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    To be honest, I just spent over an hour trying to get it to work (in C).
    It made me cry tbh.

    Perhaps you should ask around the C forums for this question - maybe someone there has more of a clue ;)

    Sorry I can't be of more assistance, but my knowledge of Windows's GDI API's is severely lacking.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • anthrax11anthrax11 Member Posts: 511
    You can easily load a bitmap using either of the WinAPI functions LoadImage or LoadBitmap. Look for their specification on MSDN.
    For jpgs I'd recommend that you find a library. I don't know of any (free) jpeg libraries written in assembler, but I think it would be possible to compile a jpg lib such as the one by the Independent JPEG Group(www.ijg.org) into a separate dll and then call the functions from the main assembly program.

    Regards,
    a11
  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    : You can easily load a bitmap using either of the WinAPI functions
    : LoadImage or LoadBitmap. Look for their specification on MSDN.
    : For jpgs I'd recommend that you find a library. I don't know of any
    : (free) jpeg libraries written in assembler, but I think it would be
    : possible to compile a jpg lib such as the one by the Independent
    : JPEG Group(www.ijg.org) into a separate dll and then call the
    : functions from the main assembly program.
    :
    : Regards,
    : a11

    Yeah but how do you display them? :P

    I tried a lot of things... I got as far as working with device contexts etc, but no matter what I did (followed multiple examples on MSDN) it wouldn't print.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • anthrax11anthrax11 Member Posts: 511
    Well, once the API gives you the handle to the bitmap you can do something like the following:

    First you need to get the Device Context(DC) of the target. The target can be either a window or the whole screen. Painting to the window means that the drawing functions won't let you paint anywhere outside the window frame. To get the DC you can use the GetDC function. Passing the window handle as the parameter gives you the DC of the window, NULL gives the DC of the screen.

    Now that you've got a destination DC, you will also need a source DC. To create that use either CreateDC or CreateCompatibleDC, the latter is suitable in most situations. Now you can associate your bitmap to the source DC using SelectObject.

    The last step is getting the bitmap onto the destination DC. BitBlt does that. Now just a little cleanup and you're done!

    To sum it up, here's some code:
    [code].data
    hBitmap HBITMAP ?
    hWnd HWND ?
    hDC HDC ?
    hSrcDC HDC ?
    hOldObj dd ?

    .code

    [color=Green]; Get the destination DC[/color]
    ; invoke GetDC, NULL
    invoke GetDC, hWnd
    mov hDC, eax

    [color=Green]; Create the source DC[/color]
    invoke CreateCompatibleDC, hDC
    mov hSrcDC, eax

    [color=Green]; Select the bitmap to the DC
    ; A newly created DC has a default object that needs to be restored later to avoid a memory leak[/color]
    invoke SelectObject, hSrcDC, hBitmap
    mov hOldObj, eax

    [color=Green]; Blit the bitmap to the destination[/color]
    invoke BitBlt, hDC, 0,0,BMPWIDTH,BMPHEIGHT, hSrcDC, 0,0, SRCCOPY

    [color=Green]; Clean up[/color]
    ; invoke ReleaseDC, NULL, hDC
    invoke ReleaseDC, hWnd, hDC
    invoke SelectObject, hSrcDC, hOldObj
    invoke DeleteDC, hSrcDC

    [color=Green]; Note that the window/screen DC was released, not deleted, because the OS uses it internally.[/color][/code]
    I hope this helps!
Sign In or Register to comment.