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.
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.
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.
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
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
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.
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...
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.