Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Tearing my hair out: drawing transparent image

Tearing my hair out: drawing transparent image

Scheduled Pinned Locked Moved Visual Basic
graphicshelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jim Taylor
    wrote on last edited by
    #1

    I'm writing an app that opens an image file, converts it to a gif, sets it transparency and then resizes it. Everything works fine until I resize the image (The transparency is lost and is replaced with black pixels). The reason is that to resize the image I am doing a matrix transform and drawing the image onto a new image. When it draws onto the new image it loses its transparency information (I think this is because the image I am getting does not have the right colour depth). I could apply the transparency after resizing but this leaves 'fuzzy edges'. Does anybody have any ideas how I could achieve drawing an image with transparent areas onto a new image. If anyone can help that would be great, I could mail the entire code if necessary, would have posted it here but its too long. Here is a small section the code: Private Sub ResizeImage(ByVal filename As String, ByVal Width As Integer, ByVal height As Integer) Dim oSourceImage As Bitmap Dim tmpBmp As Bitmap = CType(Image.FromFile(filename), Bitmap) Dim IsAlpha As Boolean = Image.IsAlphaPixelFormat(tmpBmp.PixelFormat) If IsAlpha = False Then oSourceImage = New Bitmap(tmpBmp.Width, tmpBmp.Height, PixelFormat.Format32bppArgb) Dim g As Graphics = Graphics.FromImage(oSourceImage) g.DrawImage(tmpBmp, 0, 0) g.Dispose() tmpBmp.Dispose() Else oSourceImage = tmpBmp End If 'Dim oSourceImage As Image = TransImageUtility.SetTransparentColour(Image.FromFile(filename)) If Not ((oSourceImage.Width <= Width) And (oSourceImage.Height <= height)) Then Dim oResizedImage As New Bitmap(Width, height, PixelFormat.Format32bppArgb) Dim oGraphic As Graphics = Graphics.FromImage(oResizedImage) oGraphic.CompositingQuality = CompositingQuality.HighQuality oGraphic.SmoothingMode = SmoothingMode.HighQuality oGraphic.InterpolationMode = InterpolationMode.HighQualityBicubic Dim oRectangle As New Rectangle(0, 0, Width, height) '******************************** Dim largestRatio As Double = Math.Max(CDbl(oSourceImage.Width) / Width, CDbl(oSourceImage.Height) / height) Dim posX As Single = CSng(Width * largestRatio / 2 - oSourceImage.Width / 2) Dim posY As Single = CSng(height * largestRatio / 2 - oSourceImage.Height / 2) Dim mx As New Matrix(1.0F / CSng(largestRatio), 0, 0, 1.0F / CSng(larg

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups