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

Notification

Icon
Error

Options
Go to last post Go to first unread
<?tpimp="MyRide"?>  
#1 Posted : Friday, May 12, 2006 1:21:04 AM(UTC)
<?tpimp="MyRide"?>

Rank: Member

Groups: Member
Joined: 5/12/2006(UTC)
Posts: 6

Hi All, Im trying to get some opacity/transparancy on a *.png raster. I really need some sample code to get me going (dot.newbie ;-) since im really stuck on this one Ive managed to get an exceptable result through this construction
Code:
bitmap.ColorAdjustment.AdjustHsl(-0.2, -0.5, 0.5)
But it isnt the same as adding some transparancy Ive failed to get decent results through the Transparentize method Any sample code (preferably VB) is welcome Thanx in advance //dot.newbie

Edited by user Thursday, December 20, 2007 4:34:52 PM(UTC)  | Reason: Not specified

<< Sometimes it pays to stay in bed in Monday, rather than spending the rest of the week debugging Monday's code >>
&lt;?tpimp="MyRide"?&gt;  
#2 Posted : Friday, May 12, 2006 6:12:47 PM(UTC)
<?tpimp="MyRide"?>

Rank: Member

Groups: Member
Joined: 5/12/2006(UTC)
Posts: 6

Hi all, Well eventually ive managed to get the desired result through the following construction:
Code:
OrigBitmap.Draw(NewBitmap, 0, 0, _
                           OrigBitmap.Width, OrigBitmap.Height, _
                           Aurigma.GraphicsMill.Transforms.CombineMode.Alpha, 0.2F, _
                           Aurigma.GraphicsMill.Transforms.InterpolationMode.HighQuality)
but i had to create a new bitmap and combine it with the old bitmap, i still like to know how to do this directly on the original image any ideas? //dot.newbie

Edited by user Thursday, December 20, 2007 4:33:48 PM(UTC)  | Reason: Not specified

<< Sometimes it pays to stay in bed in Monday, rather than spending the rest of the week debugging Monday's code >>
Dmitry  
#3 Posted : Sunday, May 14, 2006 9:08:09 PM(UTC)
Dmitry

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 8/3/2003(UTC)
Posts: 1,070

Thanks: 1 times
Was thanked: 12 time(s) in 12 post(s)
Hello, Could you explain your task more clearly? As I understood from your second post, you try to add transapency into your 'OrigBitmap' and before you call Draw method, you apply transparentize on 'OrigBitmap'. If you get desired result after you draw your 'OrigBitmap' on temporary bitmap - this means you add tranparency correctly. In your case, method Draw blends bitmap with transparency with colored background. If you need to add tranparency and then blend it with some background - you can use Bitmap.Channels.DiscardAlpha(yourBackgroundColor) instead of creating temporary bitmap.
Sincerely yours, Dmitry Sevostyanov UserPostedImage Follow Aurigma on Twitter!
&lt;?tpimp="MyRide"?&gt;  
#4 Posted : Sunday, May 14, 2006 11:06:15 PM(UTC)
<?tpimp="MyRide"?>

Rank: Member

Groups: Member
Joined: 5/12/2006(UTC)
Posts: 6

Hi Dmitry, I will try to explain it more clearly. I have this *.png which actually has no background, now i'd like to render this image to screen in a sort of grayed version. For this i want to be able to set some kind of transparancy/opacity on this image (its background should stay transparent and all colours in it should be diplayed with some opacity) Sofar i have not been able to do this on the original loaded image directly, but through the old/new bitmap combine method, which offcourse overlays a white canvas on top of the orginal canvas portrait with some opacity setting. The thing is i am somewhat puzzled in what direction to take here. It seems the overlay isnt the way to go but i have yet to come up with the proper solution to this problem. Thanks in advance for any light shed on this task //dot.newbie
<< Sometimes it pays to stay in bed in Monday, rather than spending the rest of the week debugging Monday's code >>
Dmitry  
#5 Posted : Monday, May 15, 2006 9:15:23 PM(UTC)
Dmitry

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 8/3/2003(UTC)
Posts: 1,070

Thanks: 1 times
Was thanked: 12 time(s) in 12 post(s)
Hello, So your task contains two items: 1. You have an image with background. You want to discard background and make it transparent. As I understood this part of work is done (because you get appropriate result after blending with temporary image); 2. You want to output image with transparent background. Do you want to draw this image on graphics or you need to put this image on some another one? Could you post your code sample of Graphics Mill for .NET usage? If you don't want to post it on the forum, you can submit case with it.

Edited by user Thursday, May 22, 2008 10:41:23 PM(UTC)  | Reason: Not specified

Sincerely yours, Dmitry Sevostyanov UserPostedImage Follow Aurigma on Twitter!
&lt;?tpimp="MyRide"?&gt;  
#6 Posted : Tuesday, May 16, 2006 3:10:16 AM(UTC)
<?tpimp="MyRide"?>

Rank: Member

Groups: Member
Joined: 5/12/2006(UTC)
Posts: 6

Hi Dmitry, Here's the code i want to use for setting some transparancy. There are comments of what i'm trying to do......it seems (after some more testing) that only the windows Explorer browser displays the *.png incorrectly (with a smudged background) when i open the same image in firefox everything looks fine... Ive included my icon 'add.png' Here's the class
Code:
Option Strict On
Option Explicit On

Imports Aurigma.GraphicsMill
Imports Aurigma.GraphicsMill.Codecs
Imports Aurigma.GraphicsMill.Transforms

Partial Class ImageParse
    Inherits System.Web.UI.Page

    'Dim color As Aurigma.GraphicsMill.RgbColorcolor = Aurigma.GraphicsMill.RgbColor.FromArgb32(&H112233)
    'Dim a As Integer = color.A
    'Dim r As Integer = color.R
    'Dim g As Integer = color.G
    'Dim b As Integer = Color.B

    'Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"d:/images/test/embededprofile.png")
    'bitmap.ColorManagement.ColorManagementEnabled = true
    'bitmap.ColorManagement.RgbColorProfile = Aurigma.GraphicsMill.ColorProfile.FromSrgb()
    'bitmap.ColorManagement.ConvertToContinuous(Aurigma.GraphicsMill.ColorSpace.Rgb, false, false)
    'bitmap.Save(@"c:/newembededprofile.jpg")
    'bitmap.Dispose();

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim OrigBitmap As New Aurigma.GraphicsMill.Bitmap(Server.MapPath("~/Images/add.png"))

        'Create new
        'Dim NewBitmap As New Aurigma.GraphicsMill.Bitmap(RgbColor.White, 35, 35, PixelFormat.Format32bppArgb)

        Dim bHasAlpha As Boolean = OrigBitmap.HasAlpha

        If bHasAlpha Then
            
            'Draw foreground image on background with transparency
            'OrigBitmap.Draw(NewBitmap, 0, 0, OrigBitmap.Width, OrigBitmap.Height, Transforms.CombineMode.Alpha, 0.2, Transforms.InterpolationMode.HighQuality)

            'OrigBitmap.ColorAdjustment.AdjustHsl(-0.2, -0.5, 0.5)

            'Somehow 8bpp indexed is stated as supported in the aurigma documentation
            'but still i need to convert to another pixelformat before i can use transparentize??

            'Convert image
            OrigBitmap.ColorManagement.Convert(PixelFormat.Format32bppArgb)

            'After conversion background is smudged!!!??? 
            'This doesnt happen in photoshop when i convert this image to rgb channels
            'and then manually set opacity and then save it to disk

            'After some more testing i came to the conclusion that the background is only smudged in Explorer not in Firefox??!!
            'Then again after i save this generated image through photoshop it displays perfectly in both browsers!!


            'If i convert with 24bpp then background becomes white, i need the *.png to retain its original background
            'OrigBitmap.ColorManagement.Convert(PixelFormat.Format24bppRgb)

            'Now apply transparancy
            OrigBitmap.Channels.Transparentize(Color.FromArgb32(0, 255, 255, 255), 1.0)


            'Try to remove background after 24bpp conversion
            'OrigBitmap.Channels.DiscardAlpha(RgbColor.White)


            'Resize image so i can see it better ;-)
            OrigBitmap.Transforms.Resize(100, 100, InterpolationMode.HighQuality)

            Dim encoderOptions As New PngEncoderOptions

            

            'Save to file to check image inside photoshop
            'OrigBitmap.Save("H:/test.png")

            'When i open *.png in photoshop cs2 everything looks fine
            'But when i open the image inside a browser background looks smudged (happens after conversion)
            'After i save this graphicsmill generated image through photoshop cs2
            'everything is fine again no smudged background !!!!!


            'Save image to response stream
            Response.Clear()
            Response.ContentType = "image/png"
            OrigBitmap.Save(Response.OutputStream, encoderOptions)


            'NewBitmap.Save(Response.OutputStream, encoderOptions)
            Response.End()

            'NewBitmap.Dispose()
            OrigBitmap.Dispose()

        End If


    End Sub

End Class

Edited by user Thursday, December 20, 2007 4:34:23 PM(UTC)  | Reason: Not specified

<?tpimp="MyRide"?> attached the following image(s):
add.png
<< Sometimes it pays to stay in bed in Monday, rather than spending the rest of the week debugging Monday's code >>
Dmitry  
#7 Posted : Tuesday, May 16, 2006 7:11:36 PM(UTC)
Dmitry

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 8/3/2003(UTC)
Posts: 1,070

Thanks: 1 times
Was thanked: 12 time(s) in 12 post(s)
Hello, Internet Explorer has a problem with PNG files with alpha-channel (argb pixel format). This problem is fixed in IE 7.0. When you re-save image by Photoshop - it, probably, saves PNG as indexed with key-color defined in palette.
Sincerely yours, Dmitry Sevostyanov UserPostedImage Follow Aurigma on Twitter!
&lt;?tpimp="MyRide"?&gt;  
#8 Posted : Tuesday, May 16, 2006 11:58:19 PM(UTC)
<?tpimp="MyRide"?>

Rank: Member

Groups: Member
Joined: 5/12/2006(UTC)
Posts: 6

Hi Dmitry, Thanks for the assistance....who could have guessed...Exploder again ;-) //dot.newbie
<< Sometimes it pays to stay in bed in Monday, rather than spending the rest of the week debugging Monday's code >>
Dmitry  
#9 Posted : Wednesday, May 17, 2006 11:54:44 AM(UTC)
Dmitry

Rank: Advanced Member

Groups: Member, Administration, Moderator
Joined: 8/3/2003(UTC)
Posts: 1,070

Thanks: 1 times
Was thanked: 12 time(s) in 12 post(s)
Hello again, We have found workaround to solve this issue in Microsoft Support: PNG Files Do Not Show Transparency in Internet Explorer. The workaround for this would be to use AlphaImageLoader filter (as described in that article), however it will work in IE only. From the other side other browsers can handle such images without any filters...
Sincerely yours, Dmitry Sevostyanov UserPostedImage Follow Aurigma on Twitter!
&lt;?tpimp="MyRide"?&gt;  
#10 Posted : Friday, May 19, 2006 1:38:01 AM(UTC)
<?tpimp="MyRide"?>

Rank: Member

Groups: Member
Joined: 5/12/2006(UTC)
Posts: 6

Hi Dmitry, Filter has a direct opacity setting which was the first thing that we used, but then no other browser would support this. That's why we resorted to graphicsmill for this specific problem. Anyway i will look into this other filter option after all then i can still use one and the same image for this purpose. Again thanks for the excellent support. //dot.newbie
<< Sometimes it pays to stay in bed in Monday, rather than spending the rest of the week debugging Monday's code >>
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.