473,404 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

drawing image as a partly transparent one

I have an icon I want to draw onto the screen, but I want to streatch it out
to be about 256x256 and make it about 75% transparent how would I go about
this? do i need to convert it to a bitmap first then paint it larger? and
how would i make the entire image transparent at 75% transparency (25%
opaque) thanks!
Nov 20 '05 #1
4 2734
* "Brian Henry" <brianiup[nospam]@adelphia.net> scripsit:
I have an icon I want to draw onto the screen, but I want to streatch it out
to be about 256x256 and make it about 75% transparent how would I go about
this? do i need to convert it to a bitmap first then paint it larger? and
how would i make the entire image transparent at 75% transparency (25%
opaque) thanks!


Quick and Dirty:

\\\
Imports System.Drawing
Imports System.Drawing.Imaging
..
..
..
Dim bo1 As Bitmap = _
DirectCast(Image.FromFile("C:\WINDOWS\ANGLER.BMP") , Bitmap)
Dim bo2 As Bitmap = _
DirectCast(Image.FromFile("C:\WINDOWS\FÄCHER.BMP") , Bitmap)
Dim bt1 As Bitmap = _
New Bitmap(bo1.Width, bo1.Height, PixelFormat.Format32bppArgb)
Dim bt2 As Bitmap = _
New Bitmap(bo2.Width, bo2.Height, PixelFormat.Format32bppArgb)
Dim g1 As Graphics = Graphics.FromImage(bt1)
Dim g2 As Graphics = Graphics.FromImage(bt2)
g1.DrawImage(bo1, 0, 0)
g2.DrawImage(bo2, 0, 0)
g1.Dispose()
g2.Dispose()
Dim i As Integer, j As Integer
For i = 0 To bt1.Width - 1
For j = 0 To bt1.Height - 1
bt1.SetPixel(i, j, Color.FromArgb(120, bt1.GetPixel(i, j)))
Next j
Next i
g1 = Graphics.FromImage(bt2)
g1.DrawImage(bt1, 0, 0)
g1.Dispose()
Me.BackgroundImage = bt2
bt1.Dispose()
bo1.Dispose()
bo2.Dispose()
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
ick, I was hopeing to go the rought of not manuall changeing the alpha
channel pixel by pixel.. I thought I saw in one of my .NET books a function
to draw a image partly transparent with out doing this.
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2g***********@uni-berlin.de...
* "Brian Henry" <brianiup[nospam]@adelphia.net> scripsit:
I have an icon I want to draw onto the screen, but I want to streatch it out to be about 256x256 and make it about 75% transparent how would I go about this? do i need to convert it to a bitmap first then paint it larger? and how would i make the entire image transparent at 75% transparency (25%
opaque) thanks!


Quick and Dirty:

\\\
Imports System.Drawing
Imports System.Drawing.Imaging
.
.
.
Dim bo1 As Bitmap = _
DirectCast(Image.FromFile("C:\WINDOWS\ANGLER.BMP") , Bitmap)
Dim bo2 As Bitmap = _
DirectCast(Image.FromFile("C:\WINDOWS\FÄCHER.BMP") , Bitmap)
Dim bt1 As Bitmap = _
New Bitmap(bo1.Width, bo1.Height, PixelFormat.Format32bppArgb)
Dim bt2 As Bitmap = _
New Bitmap(bo2.Width, bo2.Height, PixelFormat.Format32bppArgb)
Dim g1 As Graphics = Graphics.FromImage(bt1)
Dim g2 As Graphics = Graphics.FromImage(bt2)
g1.DrawImage(bo1, 0, 0)
g2.DrawImage(bo2, 0, 0)
g1.Dispose()
g2.Dispose()
Dim i As Integer, j As Integer
For i = 0 To bt1.Width - 1
For j = 0 To bt1.Height - 1
bt1.SetPixel(i, j, Color.FromArgb(120, bt1.GetPixel(i, j)))
Next j
Next i
g1 = Graphics.FromImage(bt2)
g1.DrawImage(bt1, 0, 0)
g1.Dispose()
Me.BackgroundImage = bt2
bt1.Dispose()
bo1.Dispose()
bo2.Dispose()
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #3
* "Brian Henry" <brianiup[nospam]@adelphia.net> scripsit:
ick, I was hopeing to go the rought of not manuall changeing the alpha
channel pixel by pixel.. I thought I saw in one of my .NET books a function
to draw a image partly transparent with out doing this.


Maybe using a 'ColorMatrix' will have a better performance (untested!):

<URL:http://www.google.de/groups?selm=usTMob6qDHA.2620%40TK2MSFTNGP09.phx.gb l>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
I think this may do it too... I looked it up in my .NET book and it says
this example:

' Create a clone bithman, and make it transparent
dim bmp as new bitmap("c:\image.bmp")
' define transparency level
dim transparency as single = 0.8
' create 5x5 matric with transparency val in position (4,4)
dim values()() as single = {new single(){1,0,0,0,0}, _
new single() {0,1,0,0,0}, _
new single() {0,0,1,0,0}, _
new single() {0,0,0,transparency,0}, _
new single() {0,0,0,0,1}}
' use matrix to initialize new color matrix object
dim colMatrix as new ColorMatrix(values)
' create an imageattribute object, and assign its color matrix
dim imgAttr as new imageattributes()
imgAttr.SetColorMatrix(colMatrix,ColorMatrixFlag.D efault _
colorAdjustType.Bitmap)
'draw the bitmap using specificed image attributes
gr.drawImage(bmp,new
rectangle(200,20,bmp.width,bmp.height),0,0,bmp.wid th,bmp.height, _
graphicunit.pixel,imageAttr)


"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2g***********@uni-berlin.de...
* "Brian Henry" <brianiup[nospam]@adelphia.net> scripsit:
ick, I was hopeing to go the rought of not manuall changeing the alpha
channel pixel by pixel.. I thought I saw in one of my .NET books a function to draw a image partly transparent with out doing this.
Maybe using a 'ColorMatrix' will have a better performance (untested!):

<URL:http://www.google.de/groups?selm=usT...FTNGP09.phx.gb
l>
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Roger Shrubber | last post by:
I have a page with images that the user can drag from one frame to another. I need them to see a "ghost image" of the image they are dragging, while the original stays put. I use the onmousemove...
19
by: Atif | last post by:
Hello all, In my html page I want to add an image say of 800x600. Now I want that when ever I am given two coordinates on this image say (x1, y1)=(50, 100) and (x2, y2)=(200, 300), the java script...
1
by: news.microsoft.com | last post by:
Hello group, My goal is to attach an image over another image. Top image should be transparent so the back image is visible through the top one. Bellow is a test code in VB.NET. You need to...
1
by: David Hoffer | last post by:
I am creating a custom user control and I am having problems with setting the transparent color of the bitmap. Here is my code... protected override void OnPaint( PaintEventArgs e ) { ...
2
by: Champika Nirosh | last post by:
Hi, I want to create drawing board application that can draw Line, rectagle, circle and free hand drawing. Each drawing need to be transparent, moveable (draggable), have bring to front and...
3
by: Peter Oliphant | last post by:
I'm importing a jpeg via: Bitmap* image = new Bitmap( filename ) ; Then, using the Drawing::Graphics object, I execute DrawImage( image, x, y ). My problem is that the original image was...
0
by: eruess | last post by:
Here's the scenario: I've got a whole bunch (for the sake of argument, let's say thousands) of different little 32x14 .png files that act as buttons all over a very large website. Each button...
4
by: Dale | last post by:
I am creating GIF images with transparent backgrounds on-the-fly for a web app and rendering them by using System.Drawing.Image.Save(Response.OutputStream, ImageType.GIF). I am confident that...
0
by: vladimir.knobel | last post by:
Hi everyone, I'm working in a MCMS 2002 site and for a template I need to create images on the fly. The image format of choice is PNG because this images had to have a transparent background...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.