Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
digital_willem  
#1 Posted : Thursday, June 17, 2004 9:32:00 PM(UTC)
digital_willem

Rank: Member

Groups: Member
Joined: 6/17/2004(UTC)
Posts: 9

I already saw the topic about transparent PNG's
but no solutions :)

the problem is that if i rotate an image, the background color is set to white (or other if specified)

i can't seem to get it transparent with transparentize method, the odd thing is: my loaded image gets blue ?!

here is my code (very short :))


Code:
        Dim img As GraphicsMill.Bitmap = New GraphicsMill.Bitmap
       
        img.IsLzwEnabled = True

        img.LoadFromFile("c:\krant.tif")

        img.Transforms.Rotate(340, , &H0)

        img.Channels.Transparentize(&H0, 20)


         img.Formats.SelectCurrent("gif")

        img.Formats.GifIsTransparent = True


        img.SaveToFile("c:\test.gif")

Edited by user Monday, December 24, 2007 5:18:14 PM(UTC)  | Reason: Not specified

Andrew  
#2 Posted : Thursday, June 17, 2004 10:34:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
Hello,

Please try to add this line:

Code:
img.FormatAutoSelect = False


before selecting output format.

By the way, what is a pixel format of original TIFF file? Also, could you submit case with an example of original image and result blue image?

Edited by user Friday, May 23, 2008 4:02:35 PM(UTC)  | Reason: Not specified

digital_willem  
#3 Posted : Thursday, June 17, 2004 10:40:00 PM(UTC)
digital_willem

Rank: Member

Groups: Member
Joined: 6/17/2004(UTC)
Posts: 9

the formatautoselect didn't work

if i load it from a jpeg i doesn't turn blue anymore
but the background still isn't transparent .. it does remove the background color but turns it in grey, email is on it's way :)
Andrew  
#4 Posted : Thursday, June 17, 2004 11:34:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
Thank you for posting the problem, it seems you have discovered a bug. When you call Transparentize method for grayscale bitmap (8bppGrayscale pixel format) it turns it to 32bppArgb incorrectly. Fortunately it is easily worked around by adding

Code:
img.Data.ConvertTo32bppArgb 


before transparentizing. But anyway, we will fix this problem in the next release.

However it still won't solve your problem with transparentize. When image is saved to GIF,
it is converted to 8bppIndexed pixel format (based on palette). The transparency information may lost during it.

To make GIF transparent, you should specify transparent color in palette, after you reduce colors. Here is a code sample:

Code:
Dim img As New Bitmap
img.IsLzwEnabled = True
img.LoadFromFile ("d:\[test files]\pictures\8bpp\krant.tif")

img.Transforms.Rotate 340, , ColorWhite

img.Data.ConvertTo8bppIndexed DitheringTypeNone
img.Data.Palette.SetTransparentColor ColorWhite

'img.Channels.Transparentize ColorWhite, 20

img.FormatAutoSelect = False
img.Formats.SelectCurrent ("GIF")
img.Formats.GifIsTransparent = True

img.SaveToFile ("D:\test.gif")


Please let me know if you have any questions.

Edited by user Monday, December 24, 2007 5:18:41 PM(UTC)  | Reason: Not specified

digital_willem  
#5 Posted : Sunday, June 20, 2004 4:29:00 PM(UTC)
digital_willem

Rank: Member

Groups: Member
Joined: 6/17/2004(UTC)
Posts: 9

thanks.. this works perfect :)
digital_willem  
#6 Posted : Sunday, June 20, 2004 4:41:00 PM(UTC)
digital_willem

Rank: Member

Groups: Member
Joined: 6/17/2004(UTC)
Posts: 9

it only doesn't work with tif's
but does work with a jpeg. The image (tif) doesn't turn blue anymore but still isn't transparent
Andrew  
#7 Posted : Sunday, June 20, 2004 9:10:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
That's strange. When I tested the image you sent me, it did working.

Please try to add conversion to 32-bit ARGB pixel format right after LoadFromFile:

Code:
img.Data.ConvertTo32bppArgb


It should help.

Edited by user Monday, December 24, 2007 5:18:51 PM(UTC)  | Reason: Not specified

digital_willem  
#8 Posted : Sunday, June 20, 2004 9:29:00 PM(UTC)
digital_willem

Rank: Member

Groups: Member
Joined: 6/17/2004(UTC)
Posts: 9

I can not convert it to32 rgb because the colors must be in grayscale :)
but the problem is solved:

created a grey color and used it with settransparentcolor

thanx for the help!
Andrew  
#9 Posted : Sunday, June 20, 2004 10:19:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
Image still remain gray after converting to RGB, the only problem you'll have is that it will consume more memory...

But if you resolved the problem, you can disregard this.
digital_willem  
#10 Posted : Sunday, June 20, 2004 10:31:00 PM(UTC)
digital_willem

Rank: Member

Groups: Member
Joined: 6/17/2004(UTC)
Posts: 9

hm sorry 1 minor problem :$ i forgot to mention
the image must be cmyk or greyscale .. if i convert it and call the settransparentcolor
it says i have no palette..

i tried to import a palette but doesn't seem to work..
tried the settransparentindex too

[offtopic]

effects.invert works but doenst stand in the list

[/offtopic]

Andrew  
#11 Posted : Sunday, June 20, 2004 10:44:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
> hm sorry 1 minor problem i forgot to mention
the image must be cmyk or greyscale .. if i convert it and call the settransparentcolor
it says i have no palette..


You mean that you load CMYK or grayscale image, convert it to 8-bit indexed image, and it says that no palette presented? Could you attach your code with debugger and check what pixel format the bitmap has after ConvertTo8bppIndexed?

> i tried to import a palette but doesn't seem to work..
tried the settransparentindex too


Please show code snippet how you import the palette.

> effects.invert works but doenst stand in the list

Try img.ColorAdjustment.Invert...

To tell the truth, when you use late binding you can even write img.Invert (or any other method from Effects, Transforms, ArtisticEffects, ColorAdjustment, etc). It is a side effect of multiple interfaces implementation inside single Bitmap class. But I would not recommend to use this as you will get a lot of problems if you will improve the code to use early binding.
digital_willem  
#12 Posted : Sunday, June 20, 2004 10:57:00 PM(UTC)
digital_willem

Rank: Member

Groups: Member
Joined: 6/17/2004(UTC)
Posts: 9

this is my code currently .. it doesn't work right now but shows how i thought i could import an pallette

Code:
 Dim img As GraphicsMill.Bitmap = New GraphicsMill.Bitmap

            img.IsLzwEnabled = True

            ' path to the image
            img.LoadFromFile(sforms.form1.krantpath)

            Dim pall As Array

            Dim d As Integer = img.color.CreateCmyk(55, 27, 56, 4)

            img.Unit = GraphicsMill.Unit.UnitPixel

            img.Transforms.Resize(calcDPI(126), calcDPI(187))
            img.Transforms.Rotate(345, , d)

            img.Data.ConvertTo8bppIndexed(GraphicsMill.DitheringType.DitheringTypeNone)
            pall = img.Data.Palette.ExportToArray()


            img.FormatAutoSelect = False

            img.Formats.SelectCurrent("gif")

            img.Formats.GifIsTransparent = True

            img.Data.ConvertTo8bppGrayscale(True)
            img.Data.Palette.ImportFromArray(pall, True)
            img.Data.Palette.SetTransparentColor(d)


            img.SaveToFile("c:\krant.gif")

Edited by user Monday, December 24, 2007 5:19:08 PM(UTC)  | Reason: Not specified

digital_willem  
#13 Posted : Sunday, June 20, 2004 11:09:00 PM(UTC)
digital_willem

Rank: Member

Groups: Member
Joined: 6/17/2004(UTC)
Posts: 9

if i convert it to grayscale :

Code:
img.Data.ConvertTo8bppGrayscale(True) 


and then import/generate the palette so i can use the setTransparentColor():

Code:
img.Data.Palette.GeneratePredefined(GraphicsMill.PaletteType.PaletteTypeGrayscale)


won't work either.. he still wants a palette.. if i do:

Code:
img.data.palette.setTransParentColor()


Edited by user Monday, December 24, 2007 5:19:36 PM(UTC)  | Reason: Not specified

Andrew  
#14 Posted : Sunday, June 20, 2004 11:20:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
You can use palette when pixel format is indexed, for example Format8bppIndexed (i.e. each pixel is a number specifying index in the array of colors, namely palette). Format8bppGrayscale is not a grayscale pixel format (each pixel means a level of luminosity, not palette index). So you should use ConvertTo8bppIndexed method instead of ConvertTo8bppGrayscale. If you want to have grayscale entries in palette, use PaletteTypeGrayscale as palette type. Or if source image is always grayscale, you can use adaptive palette, it will select only those colors which are actually contained in the image (i.e. levels of gray).

Please let me know if you still have any problems.
digital_willem  
#15 Posted : Sunday, June 20, 2004 11:48:00 PM(UTC)
digital_willem

Rank: Member

Groups: Member
Joined: 6/17/2004(UTC)
Posts: 9

if i use convertTo8bppGrayscale and then import the grayscale palette the image is RGB and the area which should be transparent is black ..

there is another strange thing maybe logical :)

if i call ConvertToCmyk/ConvertTo16bppAlphaGrayscale/etc right before saving the file
whether i use or don't use palette.GeneratePredefined(GraphicsMill.PaletteType.PaletteTypeGrayscale)

it still is seen as an RGB image.. ?
Andrew  
#16 Posted : Monday, June 21, 2004 12:21:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
Palette property is available only if the image has indexed pixel format, i. e. one of the following:
  • Format1bppIndexed
  • Format4bppIndexed
  • Format8bppIndexed
You can get these pixel formats only using ConvertTo8bppIndexed. Using other pixel formats (inlcuding Format8bppGrayscale, Format32bppCmyk, etc) do not use palette at all, thus using Palette property is meaningless. You either should work with palette (with indexed images), or modify alpha channel of the image yourself (e.g. with Transparentize method or any other way). However if you need to save to GIF, you will convert the image to indexed sooner or later (because GIF do not support non-indexed pixel formats).

Palettes for indexed images always contain RGB entries. It is by design. Moreover, I never heard about file formats which support non-RGB palette entries (at least none of formats supported with Graphics Mill can do that).
Andrew  
#17 Posted : Monday, June 21, 2004 12:29:00 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
Here is a code (VB6) which should work for you.

Code:
Private Sub Command1_Click()
    Dim img As New Bitmap
    img.IsLzwEnabled = True
    img.LoadFromFile ("d:\[test files]\pictures\8bpp\krant.tif")
    img.Data.ConvertTo32bppArgb 255
    img.Transforms.Rotate 340, , ColorWhite
    
    img.Data.ConvertTo8bppIndexed DitheringTypeNone, PaletteType:=PaletteTypeGrayscale
    img.Data.Palette.SetTransparentColor ColorWhite
    
    img.FormatAutoSelect = False
    img.Formats.SelectCurrent ("GIF")
    img.Formats.GifIsTransparent = True
    
    img.SaveToFile ("D:\test.gif")
End Sub


Draw attention, it is useless to call ConvertTo8bppGrayscale before saving (as in your code snippet posted above), because GIF file does not support grayscale pixel format. It just implicitly convert the image to 8-bit indexed format and your transparency modifications will be lost.

Edited by user Monday, December 24, 2007 5:19:51 PM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.