Image opacity in C#
-
Hi friends, Can you'll help me to find another way for this.. i have two bitmaps, one is the mask bitmap which is a grey scale image and another is actual image, i am applying this mask on the image, i use getpixel & setpixel to apply the color of mask image as the alpha of the other image.. for small images it is fast but it becomes slow as the image size increases.. Is there any alternate way to do so? Thanks in advance.. :-) Regards Samir
-
Hi friends, Can you'll help me to find another way for this.. i have two bitmaps, one is the mask bitmap which is a grey scale image and another is actual image, i am applying this mask on the image, i use getpixel & setpixel to apply the color of mask image as the alpha of the other image.. for small images it is fast but it becomes slow as the image size increases.. Is there any alternate way to do so? Thanks in advance.. :-) Regards Samir
VCsamir wrote:
i use getpixel & setpixel
These methods are really VERY slow. :)
VCsamir wrote:
Is there any alternate way to do so?
Yes. - One of the alternative methods is to lock the bits of your bitmap in memory and perform a direct access to the bitmap bits using
unsafe
block. There are plenty of examples and here[^] is a very brief one. - Another option is to hide this pointer arithmetic in a class and provide some fastGetPixel
andSetPixel
implementations. You can find such a class in this[^] article (it is namedUnsafeBitmap
). - The third option is using ColorMatrix[^]. Here are some examples of its usage: 1[^], 2[^]. You can find more... I'd also suggest you to have a look at this article and the other parts of the series: Image Processing for Dummies with C# and GDI+ Part 1 - Per Pixel Filters[^] I hope this helps. :) -
VCsamir wrote:
i use getpixel & setpixel
These methods are really VERY slow. :)
VCsamir wrote:
Is there any alternate way to do so?
Yes. - One of the alternative methods is to lock the bits of your bitmap in memory and perform a direct access to the bitmap bits using
unsafe
block. There are plenty of examples and here[^] is a very brief one. - Another option is to hide this pointer arithmetic in a class and provide some fastGetPixel
andSetPixel
implementations. You can find such a class in this[^] article (it is namedUnsafeBitmap
). - The third option is using ColorMatrix[^]. Here are some examples of its usage: 1[^], 2[^]. You can find more... I'd also suggest you to have a look at this article and the other parts of the series: Image Processing for Dummies with C# and GDI+ Part 1 - Per Pixel Filters[^] I hope this helps. :) -
You're welcome! :)