Does anyone use FreeImage with VB6?? I have used this combination quite a bit over the years, but am stuck on something that I can't get working.

I want to open a jpg image, rotate it by 30 degrees (or whatever) and then paste the resulting image onto another image. When the image is rotated, the overall canvas is made larger and a fill color is used for the 'empty' areas. I want those fill areas to be a transparent color. When I paste the rotated image, the background image will show through the filled areas.

I have sample code to provide if someone is interested. Of course, my code is only what I think should work and does not do what I want.

Recommended Answers

All 9 Replies

Please show thye sample code, especially te part where you need the transparency. Also include your api references - BitBlt etc..

Here is a chunk of code that I've been trying --

        Private Sub mnuTry_Click()
           Dim back_tmp As Long
           Dim iback As Long
           Dim irotate As Long
           Dim ismall As Long
           Dim icopy As Long
           Dim small_tmp As Long
           Dim back_jpg As Long
           Dim bOk
           Dim f
           Dim h As Integer
           Dim w As Integer
           Dim image_type As FREE_IMAGE_TYPE
           Dim pixel_size As Integer
           Dim bg_color As RGBQUAD
           Dim color_type As Integer

           '''''  Open the two jpg files and convert them to 32 bits
           back_tmp = FreeImage_Load(FIF_JPEG, "C:\local\background.jpg")
           iback = FreeImage_ConvertTo32Bits(back_tmp)
           FreeImage_Unload (back_tmp)

           small_tmp = FreeImage_Load(FIF_JPEG, "C:\local\rotate.jpg")
           ismall = FreeImage_ConvertTo32Bits(small_tmp)
           FreeImage_Unload (small_tmp)

           '''''  Make sure we have the right color type and the right pixel size
           image_type = FreeImage_GetImageType(ismall)
           color_type = FreeImage_GetColorType(ismall)
           If Not color_type = FIC_RGB Then
              MsgBox ("Wrong color type")
           End If
           If image_type = FIT_BITMAP Then
              pixel_size = FreeImage_GetBPP(ismall)
              If Not pixel_size = 24 And Not pixel_size = 32 Then
                 MsgBox ("Wrong pixel size")
              End If
           Else
              MsgBox ("Wrong image type")
           End If

           '''''  Build the fill color for the rotated image
           bg_color.rgbBlue = 0
           bg_color.rgbGreen = 255
           bg_color.rgbRed = 0
           bg_color.rgbReserved = 15
           FreeImage_SetTransparent ismall, True

           '''''   Rotate the image
           irotate = FreeImage_Rotate(ismall, 30, bg_color)
           FreeImage_SetTransparent irotate, True
           FreeImage_Unload (ismall)

           '''''  Paste the rotated image onto the background image
           h = FreeImage_GetHeight(irotate)
           w = FreeImage_GetWidth(irotate)

           icopy = FreeImage_Copy(irotate, 0, 0, w, h)
           f = FreeImage_Paste(iback, icopy, 300, 300, 200)
           FreeImage_Unload (irotate)
           FreeImage_Unload (icopy)

           '''''  Save the 32 bit image as png
           bOk = FreeImage_Save(FIF_PNG, iback, "C:\local\background_new.png", PNG_DEFAULT)

           '''''  Convert the image back to 24 bits and save it as jpg
           back_jpg = FreeImage_ConvertTo24Bits(iback)
           bOk = FreeImage_Save(FIF_JPEG, back_jpg, "C:\local\background_new.jpg", JPEG_QUALITYSUPERB)

           FreeImage_Unload (iback)
           FreeImage_Unload (back_jpg)
        End Sub

--------------------------------------------

I'm using FreeImage3154. I've been using this API for 6 or 7 years with good luck, but have never gotten this transparency to work. I don't understand what value I should use for the alpha channel in the line -- bg_color.rgbReserved = 15
I've tried lots of values, but can't get a transparent color.

There is a large wrapper file that comes with the API -- MFreeImage.bas

I'mm including the images used (all 1/3 size)... the original background, the original rotate, the ending background jpg and the ending background.png. (I think I've grabbed one of the ending images twice???)

Any ideas??

Sorry for my late reply. I have some sample projects from way back that will help you cut the background and show only the inner image. At home unfortunately. Will post the sample here in a day or so when I'm back home. :)

Right, attached is a sample of cutting the edges from a picture. It includes notes but you should grasp most/all of it if I look at your level coding above. It is making use of a form over, just play around with it to use on your current picture box...

Thanks AndreRet! I'll grab the sample and let you know how it goes.

Only a pleasure. I'd like to see if it worked out.

AndreRet -- Thanks for the code. That is a very cool idea.

However, the code is very similar to what I have been using... picking a transparent color and then going thru the image pixel by pixel to see if they need to be copied. My issue with that is that it is slow when dealing with big images. Your code has some efficiencies that might help a lot, so I will ty utilizing that. Will let you know how that goes.

Cool. No problem. That was about the easiest way I could find that might help solving your problem. If it worked, please mark as solved, thanx.

Transparent background requires Alpha channel. So line 24 should look like this:

ismall = FreeImage_ConvertColorDepth(small_tmp, FICF_RGB_ALPHA)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.