Question

Transparent images in VB.NET Compact Framework

Asked by: chrismalone

Hey,
I'm developing an iPhone-like slider app for the ppc in VB.NET CF.
Unfortunately you can't do transparency the normal way and you have to override the graphics drawing functions.
I've read articles on that and tried to convert the code from C# to VB and it was impossible to try and add it to my project.

Can someone please download the source to my app:
http://forum.xda-developers.com/attachment.php?attachmentid=49552&d=1189097555 (you need to create an xda-dev account aswell)

And tell me what i need to change to make the arrow.gif image transparent to the image behind it?

Cheers.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2007-09-06 at 08:08:35ID22810980
Tags

transparent

,

compact

,

image

,

framework

Topics

Windows MobileProgramming

,

.NET Framework 2.x

,

Visual Studio

Participating Experts
3
Points
0
Comments
18

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Format a datagrid in VB.Net compact framework
    Hi, I'm developing an mobile application for a Pocket PC. I'm using VB.Net compact framework in a Visual Studio .Net 2003 Environment. Does anyone know how I can make my datagrid expand the column headers to fit the header text in? At the moment the header text is cut off,...
  2. File Sending with IrDA (PPC to Others) with VB.NET
    I am currenting using "OBEX" as the servicename to send a image from a PPC to Any other device, e.g PC thru IrDA. Current my code allows me to send the file, but it doesn't appear anywhere in my PC. (It only appears to send, not sure if it really did.) Also, while...
  3. VB.NET CF - Web Services Problem
    Hello, I'm trying to get the "Hello World" web service to work. If I put the following code in a standard VB.NET project, the web service works fine and I get a messagebox that says "Hello World": Dim ws As New HelloWorldService.Test1 T...
  4. Need to start an external application using VB.net & CF￿
    I either need to be able to send VK_OFF to the keyboard or I need to be able to start and external application using VB.net w/ CF. Since I have not a clue how do send a vertual key and I have a utility the suspends the device I figured it would be easy to shell out and run t...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: jungesPosted on 2007-09-06 at 10:52:01ID: 19842269

i don't wanto to create an account. But have you already tried to use transparent png image instead?
i use png images with transparency in my project and works fine.

 

by: chrismalonePosted on 2007-09-06 at 11:15:27ID: 19842448

well i've tried transparent gif's and that didn't work.
it's a commonly known thing that .net cf doesn't do transparent images, just some people have found solutions. i just can't implement them.

btw: an updated link to the source:
http://forum.xda-developers.com/attachment.php?attachmentid=49573&d=1189102301

 

by: jungesPosted on 2007-09-06 at 11:57:47ID: 19842775

i havefolloed the link and received: "Invalid Attachment specified. If you followed a valid link, please notify the administrator"

Have you tried to use an image with "png" format?

 

by: chrismalonePosted on 2007-09-06 at 13:20:22ID: 19843379

sorry, i'm constantly updating it and i can't edit the question now that comments have been made.
please see this thread: http://forum.xda-developers.com/showthread.php?p=1482348
and download slider_source.zip from the link at the bottom of the post.

 

by: chrismalonePosted on 2007-09-06 at 17:07:59ID: 19844582

@junges: just tried with a transparent png image too. didn't work.
it's not todo with the image type it's todo with the compact framework not having transparency capabilities (well not in an easy way anyway).

 

by: HardiPosted on 2007-09-06 at 21:07:38ID: 19845333

Hi,
.NET CF doesn't support transparent images, but you can paint the transparent part of the image with the background color of the parent of the image.

You can use SDF 2.1 community edition, one of the components called PictureBox2 does that.

http://www.opennetcf.com/CompactFramework/Products/SmartDeviceFramework/tabid/65/Default.aspx

 

by: chrismalonePosted on 2007-09-07 at 02:06:15ID: 19846223

thanks hardi, i've seen similar solutions like that which don't use open .net cf but that was the easiest to setup.
it's not a practical solution though as i need it to go through to the background image and not 1 solid color.

i was able to get text to go transparently over the top of another image, why should it be so hard to do it with pictures?
isn't it possible to just not paint the pixels that are set to the transparency color?

 

by: HardiPosted on 2007-09-07 at 20:50:55ID: 19852287

I see... yeah that's what I want to know too... hehe.
I'm not really sure, but I think the area (the rectangle) occupied by the PictureBox can only be painted by the PictureBox itself. So you need to make the PictureBox paint the background image to do transparency...
Well I'm not really sure, and I would be very interested if there is a solution for this problem :-)

 

by: chrismalonePosted on 2007-09-07 at 23:58:51ID: 19852640

oh ok, thanks.
well at the moment i'm stuck with a 99% developed app that has a bitmap with an ugly color around it :(
i'd even go to the length of importing a dll that's written in native code to do the work.. if that's possible.

the other idea would be simply updating that solid color to use a pixel from the bitmap behind it, every it is moved.
the main trouble is that the bitmap can be moved (dragged).

if anyone has ANY idea and can implement it in my project please share it.

 

by: chrismalonePosted on 2007-09-09 at 06:13:43ID: 19856683

i found this:
http://www.opennetcf.com/Default.aspx?tabid=130

but it's impossible to get it to work.
and for some reason i can't implement IDisposable in vb.net but i can in c#.net ... :(

i'll add extra points if anyone can solve this problem and show me how i can add it to my project.

 

by: chrismalonePosted on 2007-09-11 at 12:36:07ID: 19871558

ok i've made a new picturebox class that inherits from picturebox, and it does the transparency.
the only problem is that if i don't put a picture behind it, it will just show underneath the form instead of just being transparent to the picture behind it.
so i've put the picture behind it.
now the problem is that the image has to move, so i'd have to make it repaint it every time so the image behind it is right.
i need to use a function similar to what's commented out. (it causes errors though) -

Public Class PictureBoxEX
    Inherits PictureBox

    Protected Overloads Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim attr As New Imaging.ImageAttributes()
        attr.SetColorKey(Color.FromArgb(255, 0, 255), Color.FromArgb(255, 0, 255))
        e.Graphics.DrawImage(Me.Image, Me.ClientRectangle, 0, 0, Me.Image.Width, Me.Image.Height, GraphicsUnit.Pixel, attr)
    End Sub

    Protected Overloads Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim attr As New Imaging.ImageAttributes()
        attr.SetColorKey(Color.FromArgb(255, 0, 255), Color.FromArgb(255, 0, 255))
        e.Graphics.DrawImage(Slider.sbgimg, Me.ClientRectangle, 0, 0, Me.Image.Width, Me.Image.Height, GraphicsUnit.Pixel, attr)
    End Sub


    'Public Sub rePaint()
    'Dim attr As New Imaging.ImageAttributes()
    '   attr.SetColorKey(Color.FromArgb(255, 0, 255), Color.FromArgb(255, 0, 255))
    '   Me.CreateGraphics.DrawImage(Slider.sbgimg, Me.ClientRectangle, 0, 0, Me.Image.Width, Me.Image.Height, GraphicsUnit.Pixel, attr)
    '   Me.CreateGraphics.DrawImage(Me.Image, Me.ClientRectangle, 0, 0, Me.Image.Width, Me.Image.Height, GraphicsUnit.Pixel, attr)
    'End Sub

End Class

every time the picture moves i need to be able to redraw the image somehow..
anyone got any ideas?

 

by: HardiPosted on 2007-09-11 at 19:18:15ID: 19873481

Wow you did it!

How do you move the image? Perhaps on the MouseUp event handler add Refresh()?

 

by: chrismalonePosted on 2007-09-11 at 21:53:58ID: 19873973

yer i've tried refresh. doesn't do anything for some reason..

 

by: HardiPosted on 2007-09-12 at 16:38:49ID: 19880694

chrismalone, have you seen this
http://msdn2.microsoft.com/en-us/library/aa446533.aspx#netcfgaming_topic3

I don't really understand it but hope it can help you.
Find "dirty area"

 

by: chrismalonePosted on 2007-09-12 at 17:07:14ID: 19880789

i solved it.
i had to calculate the relative position of the image ontop of the other one and then draw it, then crop that area behind it, and return it to the image on the onpaintbackground event.
@hardi: in the article you just listed it basically says that's inefficient. and it is.
but it's the only way i could get it to work.
anyways here's the class i created:

Public Class PictureBoxEX
    Inherits PictureBox

    Protected Overloads Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim attr As New Imaging.ImageAttributes()
        attr.SetColorKey(Color.FromArgb(255, 0, 255), Color.FromArgb(255, 0, 255))
        e.Graphics.DrawImage(Me.Image, Me.ClientRectangle, 0, 0, Me.Image.Width, Me.Image.Height, GraphicsUnit.Pixel, attr)
        e.Graphics.Dispose()
    End Sub

    Protected Overloads Overrides Sub OnPaintBackground(ByVal e As System.Windows.Forms.PaintEventArgs)
        e.Graphics.DrawImage(saveimage(Me.Width, Me.Height, Me.Left - Slider.SliderBG.Left, Me.Top - Slider.SliderBG.Top), 0, 0)
        e.Graphics.Dispose()
    End Sub


    Public Function saveimage(ByVal width As Integer, ByVal height As Integer, ByVal locationx As Integer, ByVal locationy As Integer) As Bitmap
        Dim attr As New Imaging.ImageAttributes

        Dim cropped As New Bitmap(width, height)
        Dim g As Graphics = Graphics.FromImage(cropped)
        g.DrawImage(Slider.sbgimg, New Rectangle(0, 0, cropped.Width, cropped.Height), locationx, locationy, cropped.Width, cropped.Height, GraphicsUnit.Pixel, attr)
        g.Dispose()

        Return cropped
    End Function
End Class

 

by: HardiPosted on 2007-09-12 at 19:43:24ID: 19881321

Congratulations! :-D
Thanks for sharing the code

 

by: Computer101Posted on 2007-10-18 at 18:22:33ID: 20105857

PAQed with points refunded (500)

Computer101
EE Admin

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...