Graphics processing in Jade

Forums for specific tips, techniques and example code
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Graphics processing in Jade

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:37 pm

by johnmunro >> Wed, 1 May 2002 16:31:21 GMT

Hi guys - long time listener, first time caller :)

I need to do a lot of stuff to a TIFF file. Jade doesn't view multi-page TIFF's, so I've written code to take a multi-page TIFF and split it into one single page TIFF per page. This works well. I will also soon write code to put the pages back together into a multi-page TIFF for saving back to the hard drive. I can do all of the splitting/combining using Jade Binary primitives in memory, then put this into the picture property of the picturebox, so it's nice and neat.

The problem I'm having is the processing on the image that I'm going to do to the image between the loading and the saving - i.e. the major part of the application :). To begin with, I need to be able to resize the image to a user-selectable zoom level and pan around it if the picture box is smaller than the image.

You'd think this would be fairly easy - stick the binary into a picturebox with stretch set to 'stretch picture to control' and then resize the picturebox relative to the amount of zoom (or use drawPictureIn, same basic result). The problem is that our application deals with scanned images - in almost all cases black and white. When you zoom out, there is a lot of distortion (see the attachment standard.png). We can get over this by using the pixels that are hidden by zooming out to modify the pixels that are visible, resulting in a much more readable image (see the attachment interpol.png).

There is a very useful API call - SetStretchBltMode, which when set to the right mode will achieve the desired effect on a bitmap which has been stretched using the StretchBlt API call. I've made a quick VB program to test this, and it does everything I want it to.

The problem (and reason for this email) is that the whole StretchBlt thing needs to operate on a DC (which I'm assuming I can get from the hWnd of the picturebox using the getDC API call) which has had a GDI bitmap selected into it using the SelectObject API call. I can't seem to get a handle to the bitmap of the picturebox. The picture property of the picturebox is a Jade Bitmap primitive type, and so is no use as a GDI bitmap.

I've tried using SetStretchBltMode on the picturebox and then using the Jade method drawPictureIn, but it didn't interpolate the missing pixels as it should.

The first thing everyone is going to say is to use an external control or DLL. I want to avoid ActiveX/DLL usage as much as possible, because of the issues with maintainability of clients and also the difficulties in moving bitmaps between Jade and ActiveX.

John Munro
Synergist Limited - Home of FileVisionT
The Bioscience Innovation Centre
Cowley Road, Cambridge, UK
CB4 0DS
Telephone: +44 (0) 1223 478200
Fax: +44 (0) 1223 477969
Email: john.munro@filevision.com
Web: http://www.filevision.com
The contents of this communication are confidential and are only intended to be read by the addressee. We apologize if you receive this communication in error and ask that you contact Synergist Limited immediately to arrange for its return. The use of any information contained in this communication by an unauthorized person is strictly prohibited. Synergist Limited cannot accept responsibility for the accuracy or completeness of this communication as it is being transmitted over a public network. If you suspect this message may have been intercepted or amended, please inform Synergist Limited.
Attachments
2214_2.png
2214_2.png (5.24 KiB) Viewed 4436 times
2214_1.png
2214_1.png (1.15 KiB) Viewed 4436 times
Last edited by ConvertFromOldNGs on Fri Aug 07, 2009 4:01 pm, edited 2 times in total.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Graphics processing in Jade

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:37 pm

by cdshearer >> Wed, 1 May 2002 20:30:57 GMT

Hi John

Long time listener, long time caller too... welcome aboard.

Firstly, I can't claim to have too much experience in this area of image manipulation, and it's been a long time since I looked into using the GDI Windows API functions. However, I would think that the problem you're having is that you're setting a mode on the DC (using your call to SetStretchBltMode), and JADE probably overrides that when it draws a picture in a Picture control.

I've just done a little test, trying calling the SetStretchBltMode function on a Picture control. Here's my code:

vars
dc : Integer;begin

dc := call getDC(picture1.hwnd);
write "setting";
write call setStretchBltMode(dc, 4);
write "getting";
write call getStretchBltMode(dc);
end;

This code runs in response to a button click. When I try it, the call to getStretchBltMode returns 4, which is what I set. However, if I call the function again, from a separate button, it always returns 1 (which seems to be the default mode).

It would seem that JADE is somehow overriding the mode. I would think, however, that you could just use the DC you get, and after setting the Stretch mode, just use the DC with Windows API functions to draw on the picture control. That would be what JADE is doing, but it just doesn't allow you to set the stretch mode.

Unfortunately, I don't have enough experience with these functions... but I'm sure you do. Try it out and let us know how it goes...

Craig

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Graphics processing in Jade

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:37 pm

by johnmunro >> Fri, 3 May 2002 12:23:43 GMT
I would think,
however, that you could just use the DC you get, and after setting the Stretch mode, just use the DC with Windows API functions to draw on the picture control. That would be what JADE is doing, but it just doesn't allow you to set the stretch mode.

The problem is more than just the stretch mode - if you just do a StretchBlt from a picturebox to another one, it seems to copy whatever's on the screen, rather than the source bitmap. You can test this by copying more than the size of the source picture box. The reason this causes a problem is that in order to make a copy of the source picture at a different zoom, you would need to have a picturebox which showed the entire picture. If you made this picturebox invisible, the StretchBlt would just copy what is on the screen at the coordinates of the invisible picturebox, rather than the source bitmap. If you put the picturebox off the screen, StretchBlt copies white.
This problem is sorted by using SelectObject to select the source bitmap (accessed through the picturebox.picture property in VB, which doesn't seem to have a Jade equivalent) into the DC. This seems to enable StretchBlt to copy from the source bitmap rather than from the screen. My problem is that I can't find a way in Jade of getting a handle to the source bitmap.

--
John Munro
Synergist Limited - Home of FileVisionT
The Bioscience Innovation Centre
Cowley Road, Cambridge, UK
CB4 0DS
Telephone: +44 (0) 1223 478200
Fax: +44 (0) 1223 477969
Email: john.munro@filevision.com
Web: http://www.filevision.com
The contents of this communication are confidential and are only intended to be read by the addressee. We apologize if you receive this communication in error and ask that you contact Synergist Limited immediately to arrange for its return. The use of any information contained in this communication by an unauthorized person is strictly prohibited. Synergist Limited cannot accept responsibility for the accuracy or completeness of this communication as it is being transmitted over a public network. If you suspect this message may have been intercepted or amended, please inform Synergist Limited.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Graphics processing in Jade

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:37 pm

by CarlRanson >> Wed, 1 May 2002 22:55:32 GMT

I've done this before. Using the native windows apis for bitmaps is hard work in Jade.

The first and most bothersome problem is to do with what jade stores as a picture. You'll find that a picture binary in jade is simply a direct copy of the file contents. This is NOT what the windows api's use.

If you call the loadBitmap api to get a bitmap file from disk, it seems to do some processing (don't know what it does) to give you a binary representation. Finding this out involved a lot of time in a hex editor and at the MSDN site going through the data structure documentation.

I was trying to employ the bitBlit call to do a semi transparent draw. The solution at the time for me was to write a small dll in delphi that mangled the jade representation into something the windows api would accept. Don't have the code handy, so I can't tell you exactly what was required.

Hope that helps
CR

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Graphics processing in Jade

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:37 pm

by johnmunro >> Fri, 3 May 2002 12:35:14 GMT
The solution at the time for me was to write a small dll in delphi that mangled the jade representation into something the windows api would accept.

Wow, um, if at all possible I would like to avoid having to turn the internal TIFF representation of a bitmap into the internal GDI representation of a bitmap... especially as Jade is obviously already doing it in order to display TIFF files in pictureboxes...

--
John Munro
Synergist Limited - Home of FileVisionT
The Bioscience Innovation Centre
Cowley Road, Cambridge, UK
CB4 0DS
Telephone: +44 (0) 1223 478200
Fax: +44 (0) 1223 477969
Email: john.munro@filevision.com
Web: http://www.filevision.com
The contents of this communication are confidential and are only intended to be read by the addressee. We apologize if you receive this communication in error and ask that you contact Synergist Limited immediately to arrange for its return. The use of any information contained in this communication by an unauthorized person is strictly prohibited. Synergist Limited cannot accept responsibility for the accuracy or completeness of this communication as it is being transmitted over a public network. If you suspect this message may have been intercepted or amended, please inform Synergist Limited.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Graphics processing in Jade

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:37 pm

by CarlRanson >> Sun, 5 May 2002 21:49:54 GMT
The solution at the time for me was to write a small dll in delphi that mangled the jade representation into something the windows api would accept.

Wow, um, if at all possible I would like to avoid having to turn the internal TIFF representation of a bitmap into the internal GDI representation of a bitmap... especially as Jade is obviously already doing it in order to display TIFF files in pictureboxes...

Well, then, I suggest you have two options.

1. Find a way to get windows to do the conversion for you. This basically boils down to avoiding the jade drawing facilities yourself and using the windows APIs load the picture (loadBitmap) and the scale and draw it appropriately (stretchBlt or StretchDIBits).

2. Convince Jade that they need to provide methods to access structures compatible with the windows APIs. They seem to have a desire to hide all the details away from us, rather than provide access into the technical stuff if necessary.

If it were me, I'd go with option one. Its more work, but at least its under your control and you'll learn a lot about how windows works in the process. There's also plenty of source code examples you can copy from on the MSDN site.

Keep us informed:
CR

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: Graphics processing in Jade

Postby ConvertFromOldNGs » Fri Aug 07, 2009 2:37 pm

by johnmunro >> Tue, 7 May 2002 9:17:00 GMT
1. Find a way to get windows to do the conversion for you. This basically boils down to avoiding the jade drawing facilities yourself and using the windows APIs load the picture (loadBitmap) and the scale and draw it appropriately (stretchBlt or StretchDIBits).

The problem is there's no API for TIFF files - loadBitmap doesn't work on them...
2. Convince Jade that they need to provide methods to access structures compatible with the windows APIs. They seem to have a desire to hide all the details away from us, rather than provide access into the technical stuff if necessary.

At the moment all I need is a reference to the hBMP (handle to the API bitmap) that I assume the Jade picturebox is already creating and using. If it isn't then I'm pretty much stuffed...

--
John Munro
Synergist Limited - Home of FileVisionT
The Bioscience Innovation Centre
Cowley Road, Cambridge, UK
CB4 0DS
Telephone: +44 (0) 1223 478200
Fax: +44 (0) 1223 477969
Email: john.munro@filevision.com
Web: http://www.filevision.com
The contents of this communication are confidential and are only intended to be read by the addressee. We apologize if you receive this communication in error and ask that you contact Synergist Limited immediately to arrange for its return. The use of any information contained in this communication by an unauthorized person is strictly prohibited. Synergist Limited cannot accept responsibility for the accuracy or completeness of this communication as it is being transmitted over a public network. If you suspect this message may have been intercepted or amended, please inform Synergist Limited.


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 10 guests