System.Drawing.Graphics.DrawImage
, başka bir görüntüyü yapıştırır. Ancak bir şeffaflık seçeneği bulamadım.System.Drawing.Image semitransparent nasıl oluşturulur?
, ben sadece saydam (alfa-şeffaflık)
System.Drawing.Graphics.DrawImage
, başka bir görüntüyü yapıştırır. Ancak bir şeffaflık seçeneği bulamadım.System.Drawing.Image semitransparent nasıl oluşturulur?
, ben sadece saydam (alfa-şeffaflık)
"Saydamlık" seçeneği yoktur çünkü yapmaya çalıştığınız şey Alfa Harmanlaması olarak adlandırılmaktadır.
public static class BitmapExtensions
{
public static Image SetOpacity(this Image image, float opacity)
{
var colorMatrix = new ColorMatrix();
colorMatrix.Matrix33 = opacity;
var imageAttributes = new ImageAttributes();
imageAttributes.SetColorMatrix(
colorMatrix,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
var output = new Bitmap(image.Width, image.Height);
using (var gfx = Graphics.FromImage(output))
{
gfx.SmoothingMode = SmoothingMode.AntiAlias;
gfx.DrawImage(
image,
new Rectangle(0, 0, image.Width, image.Height),
0,
0,
image.Width,
image.Height,
GraphicsUnit.Pixel,
imageAttributes);
}
return output;
}
}
[ColorMatrix] (http://msdn.microsoft.com/en-us/library/system.drawing.imaging.colormatrix (v = vs.110) .aspx) + [ImageAttributes] (http://msdn.microsoft.com/en-us/library/system.drawing.imaging.imageattributes (v = vs.110) .aspx) + [SmoothingMode] (http://msdn.microsoft.com/en-us/library/z714w2y9(v=vs.110).aspx) – Bitterblue
Bana göre çalışacağını düşünüyorum Mitch sağlanan bağlantıyı bir cevap kopyalanan yapmak istiyorum :
public static Bitmap SetOpacity(this Bitmap bitmap, int alpha)
{
var output = new Bitmap(bitmap.Width, bitmap.Height);
foreach (var i in Enumerable.Range(0, output.Palette.Entries.Length))
{
var color = output.Palette.Entries[i];
output.Palette.Entries[i] =
Color.FromArgb(alpha, color.R, color.G, color.B);
}
BitmapData src = bitmap.LockBits(
new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.ReadOnly,
bitmap.PixelFormat);
BitmapData dst = output.LockBits(
new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.WriteOnly,
output.PixelFormat);
bitmap.UnlockBits(src);
output.UnlockBits(dst);
return output;
}
, Bitmap.Pallete.Entries boş olduğu için çalışmadı –
private Image GetTransparentImage(Image image, int alpha)
{
Bitmap output = new Bitmap(image);
for (int x = 0; x < output.Width; x++)
{
for (int y = 0; y < output.Height; y++)
{
Color color = output.GetPixel(x, y);
output.SetPixel(x, y, Color.FromArgb(alpha, color.R, color.G, color.B));
}
}
return output;
}
http://stackoverflow.com/questions/189392/how-do-you-draw-transparent-image-using-system-drawing –
@Mitch Buğday - bu soruyu GIF'lere özgüdür – Oded
GIF’lerin yarı saydamlığı yoktur. Burada PNG'ler hakkında konuşuyorum –