I'm asking too many of these questions:D anyways, I can't figure out how. :( I couldnt find anything on the internet either
Printable View
I'm asking too many of these questions:D anyways, I can't figure out how. :( I couldnt find anything on the internet either
no, I want to apply a texture to a bitmap, as I said :) I dont know how else to say it:D here, I'll show you an example:Quote:
http://www.vbforums.com/attachment.php?postid=1415255
I guess you are writing 'Mr.Polite Photoshop' to replace 'Adobe Photoshop' . Great! We back you all. Good Luck ;)
ok I started working on this crappy program of mine again... I thought a little about this texture thing and I figured it out.Quote:
Originally posted by Lunatic3
I guess you are writing 'Mr.Polite Photoshop' to replace 'Adobe Photoshop' . Great! We back you all. Good Luck ;)
here's what I do: I convert the texture to grayscale. The whitemost pixels (highest r, g, or b value) will have the most transparency. The darkmost pixels will be the least transparent pixels when you are applying the texture:
I just copy pasted my code from my project... you can combine all those a3 functions for converting to grayscale if you wantVB Code:
' Modifies the ORIGINAL bitmap and also returns a reference to it Public Shared Function ApplyTexture(ByRef bmp As Bitmap, ByVal textureTransparency As Single) As Bitmap If bmp Is Nothing Then Throw New ArgumentNullException If textureTransparency < 0 OrElse textureTransparency > 1 Then Throw New ArgumentOutOfRangeException("textureTransparency must be between 0 and 1.") End If bmp = MakeImageGrayscale(bmp) Dim x, y As Integer Dim alpha As Integer For x = 0 To bmp.Width - 1 For y = 0 To bmp.Height - 1 Dim c As Color = bmp.GetPixel(x, y) ' c.R -> all of the RGB values are the same since the image is grayscale. alpha = CInt(c.R * textureTransparency) c = Color.FromArgb(alpha, c) bmp.SetPixel(x, y, c) Next Next Return bmp End Function Public Shared Function MakeImageGrayscale(ByVal bmp As Bitmap) As Bitmap Dim imageAttrib As ImageAttributes = GetGrayscaleAttr() Return ApplyImageAttribute(bmp, imageAttrib) End Function Public Shared Function GetGrayscaleAttr() As ImageAttributes Dim values()() As Single = {New Single() {0.5, 0.5, 0.5, 0, 0}, _ New Single() {0.5, 0.5, 0.5, 0, 0}, _ New Single() {0.5, 0.5, 0.5, 0, 0}, _ New Single() {0, 0, 0, 1, 0}, _ New Single() {0, 0, 0, 0, 1}} ' Use the matrix to initialize a new colorMatrix object Dim colMatrix As New ColorMatrix(values) Dim imageAttr As New ImageAttributes imageAttr.SetColorMatrix(colMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap) Return imageAttr End Function Public Shared Function ApplyImageAttribute(ByVal img As Bitmap, ByVal imageAttrib As ImageAttributes) As Bitmap Dim bmp As New Bitmap(img.Width, img.Height) Dim gr As Graphics = Graphics.FromImage(bmp) gr.DrawImage(img, New Rectangle(0, 0, img.Width, img.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel, imageAttrib) Return bmp End Function
edit: ahem, would it be more efficient if I converted the image to grayscale myself in that first forloop? or would applying an image attribute be faster?