1. Simplest way to display Image???

What is the easiest way to: 1>Load a JPG file 2>Resize to fit into an area on the screen? 3>Zoom in (Not necessary at the moment but may be desirable in the future)

This is a windows program using WIN32LIB

new topic     » topic index » view message » categorize

2. Re: Simplest way to display Image???

I was thinking of using CXImage

What are you opinions on this.

After loading into an atom I think how do I display it.

Never done this before.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Simplest way to display Image???

lockiedownunder said...

What is the easiest way to: 1>Load a JPG file 2>Resize to fit into an area on the screen? 3>Zoom in (Not necessary at the moment but may be desirable in the future)

This is a windows program using WIN32LIB

Check out Tommy Carlier's Win32Dib and FreeDib. I used those for a graphics manipulation program a few years back. They might be out of date now, but I remember them making things easier for me. blink

new topic     » goto parent     » topic index » view message » categorize

4. Re: Simplest way to display Image???

Here's a function that will create a proper Win32Lib DIB from a CxImage object. I just took createDIB(), ripped out the EuBmp guts and stuffed in some CxImage calls. Enjoy! smile

global function createDIBFromCXImage( atom image )
 
    sequence info, pal 
    integer width, height, bitsPer, colors, headerSize 
    atom mset, memBits, memBitmapInfo, at, hdc, hDIB 
     
    mset = w32new_memset() 
     
    -- get the dib info 
    info = CXI_GetDIB( image ) 
    memBits = info[1] 
    width   = info[2] 
    height  = info[3] 
    bitsPer = info[4] 
     
    -- get the palette 
    pal = CXI_GetPalette( image ) 
     
    -- determine number of colors 
    colors = length( pal ) 
     
    -- determine the header size 
    headerSize = SIZEOF_BITMAPINFOHEADER + (SIZEOF_RGBQUAD * colors) 
     
    -- allocate memory for DIB 
    memBitmapInfo = w32acquire_mem( mset, headerSize ) 
    w32set_memory( memBitmapInfo, ID_BITMAPINFOHEADER, 
        {SIZEOF_BITMAPINFOHEADER, width, height, 1, bitsPer, 0, 0, 0, 0, colors, 0} ) 
     
    -- get the address of the first rgb tuple 
    at = w32address( memBitmapInfo, bmiColors ) 
 
    -- copy the pal to memory 
    for i = 1 to colors do 
 
        -- store values 
        w32store( at, rgbRed, pal[i][1] ) 
        w32store( at, rgbGreen, pal[i][2] ) 
        w32store( at, rgbBlue, pal[i][3] ) 
        w32store( at, rgbReserved, 0 ) 
 
        -- move to next quad 
        at += SIZEOF_RGBQUAD 
 
    end for 
     
    -- Get the screen's device context. 
    hdc = getDC( Screen ) 
 
    -- Create the DIB. 
    hDIB = w32Func( xCreateDIBitmap, { 
            hdc, 
            w32address( memBitmapInfo, bmiHeader ), 
            CBM_INIT, 
            memBits, 
            memBitmapInfo, 
            DIB_RGB_COLORS} ) 
 
    -- release the screen dc 
    releaseDC( Screen ) 
 
    -- Free memory 
    w32release_mem( mset ) 
 
    trackObject( {-1,kBitmapObject}, hDIB, ForProgram ) 
 
    return hDIB 
end function 

-Greg

new topic     » goto parent     » topic index » view message » categorize

5. Re: Simplest way to display Image???

Man thats a lot of work to display an image.

Thank you it works well :)

Now I just have to work out how to resize, zoom and move image so I can see it better.

Any help welcome

new topic     » goto parent     » topic index » view message » categorize

6. Re: Simplest way to display Image???

Ok resizing with cximage is pretty easy - got that covered

HOW would I scroll an image thats larger then my bitmap area

OR

HOW can I click on the image and resize/zoom in so that the clicked point is the centre of my display.

Thanks Tony

new topic     » goto parent     » topic index » view message » categorize

7. Re: Simplest way to display Image???

ANYONE?

HOW would I scroll an image thats larger then my bitmap area

OR

HOW can I click on the image and resize/zoom in so that the clicked point is the centre of my display.

Thanks Tony

new topic     » goto parent     » topic index » view message » categorize

8. Re: Simplest way to display Image???

lockiedownunder said...

ANYONE?

HOW would I scroll an image thats larger then my bitmap area

OR

HOW can I click on the image and resize/zoom in so that the clicked point is the centre of my display.

Thanks Tony

Assuming you have gotten the image into RAM as a DIB (Device Independant Bitmap) then ...

  • Scrolling. I assume you have a "viewport" into the bitmap such that the viewport cannot display the entire bitmap at once.
    • Use bitBlt or copyBlt and set the destination offset to negative offsets.
    • For example, if you set the X/Y destination to -100,-200 the the effect is to show position 100,200 of the bitmap in the top left corner of the viewport.
    • You can scroll the image this way by linking the relative offset of the ButtonDown location to the viewport's topleft as the delta to apply to the bitBlt destination offset.
    • For example, let's assume that the user clicks and holds down the mouse at position 50 pixels to the right of the viewport's left edge, and 75 pixels from the top of the viewport's top edge - (50,75). Now track the mouse movements and subtract each mouse position from this (50,75).
    • Eg. The mouse moves to (40,68) which means the relative mouse movement is (-10, -7), that is 10 pixels left and 7 pixels up. So now you bitBlt the image to the destination offset (-10,-7) which has the effect of move the image left 10 pixels and up 7 pixels.
    • Now if the mouse position next is (45,67) we still subtract the initial mouse location from this giving (-5, -8), and again you bitBlt the image to destination (-5, -8), this moving the image by the same amont you moved the mouse.
    • On receiving a ButtonUp event you can stop moving the image around.
  • Zooming.
    • Use the stretchBlt to create an enlarged/reduced copy of your original DIB by the parameters you supply. These can be based on the mouse's scrollwheel movement, for example. You then display the new DIB in the viewport.

My technique is to store DIBs in a Pixmap control and bitBlt them to a viewport during its Paint event. If you need better performance, you can calculate which portion of the DIB needs to be bitBlt'ed by using the parameters on the Paint event. This can sometimes improve things by not having to reshow the entire DIB, just the parts that have been exposed.

new topic     » goto parent     » topic index » view message » categorize

9. Re: Simplest way to display Image???

Hello Derek, nice to see that your are still around, I have been away for a long while.

I am using a WIN32LIB BitmapImage to display the picture.

image = CXI_LoadImage("CMI16.jpg", CXI_FORMAT_UNKNOWN, 0) 
setBitmap(BitmapImage,createDIBFromCXImage(image)) 

image is the hDIB

Sorry I am really struggling with this, I played around with bitBlt & copyBlt but I don't understand.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu