|
-
Nov 16th, 2009, 07:18 PM
#1
Thread Starter
Frenzied Member
Need to draw a simple image
I need to create a function which accepts a single value of integer which specifies the width/height of the resulting image, which will only have a single black pixel in the upper left corner and the rest being transparent and saved as a gif file. Any help on this would be appreciated.
-
Nov 16th, 2009, 07:47 PM
#2
Re: Need to draw a simple image
Is this the kind of thing you are looking for?
Code:
Function GIFBitmap(ByVal x As Integer, ByVal filename As String) As Boolean
Dim result As Boolean
Try
Dim bmp As New Bitmap(x, x)
bmp.SetPixel(0, 0, Color.Black)
bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Gif)
result = True
Catch
result = False
End Try
Return result
End Function
This would work, since a new bitmap declared only with its width and height is transparent so you only need to set the one pixel.
EDIT: No, I was wrong. Apparently Bitmap.Save doesn't save the transparency to a GIF file, so the transparent part will show up as black. You can find an explanation of how to make a transparent GIF (in Cs and VB.Net) here: http://www.bobpowell.net/giftransparency.htm
I don't have time to look at that myself now, but perhaps you can use it. I'll leave my Function code above since it may still be useful.
cheers, BB
Last edited by boops boops; Nov 16th, 2009 at 08:22 PM.
-
Nov 17th, 2009, 11:06 AM
#3
Thread Starter
Frenzied Member
Re: Need to draw a simple image
Ya, I think I saw that bobpowell link before and thought, wow, it can't be that hard to make a transparent image, can it?? As it turns out, there is a maketransparent comment in .NET, but it doesn't seem to work...
-
Nov 17th, 2009, 12:08 PM
#4
Re: Need to draw a simple image
 Originally Posted by dbassettt74
Ya, I think I saw that bobpowell link before and thought, wow, it can't be that hard to make a transparent image, can it?? As it turns out, there is a maketransparent comment in .NET, but it doesn't seem to work...
I agree, that example is overcomplicated and it is full of stuff that was needed with VB6 or VB2003 but is no longer necessary. It does show that it's possible to save GIFs with transparency, though, and I'm sure it will be possible to boil it down to a dozen or so lines of code. I'll try to find time to look at it in the next few days, assuming no one comes up with something first.
MakeTransparent works on bitmaps, and you can do all kinds of things with transparency in GDI+. The problem is saving an image to a GIF, because the Save methods don't update the GIF palette with transparent colours. (Are you sure you need to use GIF files, by the way? )
cheers, BB
-
Nov 17th, 2009, 02:20 PM
#5
Thread Starter
Frenzied Member
Re: Need to draw a simple image
I'm not sure if I "need" a gif file, but what I need is to produce some sort of transparent image with a single black dot in the upper left corner, to eventually be displayed by a web browser. So the web browsers has to render it has a transparent background. I thought this was only possible with a "gif", but maybe I'm wrong??
-
Nov 17th, 2009, 03:29 PM
#6
Re: Need to draw a simple image
The function I gave you in #2 will certainly work if you change the ImageFormat to Png or Bmp. They both save transparency data in the form of an Alpha byte for each pixel. Whether that data gets interpreted as "transparency" depends on the program reading it. GDI+ and many graphic programs treat it as you would expect. I'm sorry but I know next to nothing about web browsers, so perhaps someone else can advise you on that.
cheers, BB
-
Nov 17th, 2009, 04:04 PM
#7
Re: Need to draw a simple image
Png images will display fine in a web browser, Dbassette.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|