기본적으로 투명한 배경이있는 두 개의 .PNG 이미지가 겹치기를 원합니다. 하나는 마우스 위치로 회전하는 산탄 총으로, 다른 하나는 산탄 총 뒤에 놓고 싶은 만화 캐릭터입니다. 문제는 PNG 이미지가 겹쳐 질 때마다 PNG 이미지가 투명하게 보이고 사수가 전혀 보이지 않는다는 것입니다.PNG 이미지 오버레이 투명도 유지
나는 범인을 패널에 넣으려고했지만 샷건 그림 상자를 회전 알고리즘에 끼워 넣었다. (매우 천천히 돌린다.) 왜 그런지 모르겠다.
도움이 필요하시면 감사하겠습니다.
코딩 내가 사용 : 회전 알고리즘을 :
당신이 32 BPP 또는 64 BPP의 픽셀 형식 중 하나를 사용하기 위해 새 비트 맵 시도를 만드는private Bitmap rotateImage(Bitmap b, float angle)
{
//create a new empty bitmap to hold rotated image
Bitmap returnBitmap = new Bitmap(b.Width, b.Height);
//make a graphics object from the empty bitmap
Graphics g = Graphics.FromImage(returnBitmap);
//move rotation point to center of image
g.TranslateTransform((float)b.Width/2, (float)b.Height/2);
//rotate
g.RotateTransform((int)angle);
//move image back
g.TranslateTransform(-(float)b.Width/2, -(float)b.Height/2);
//draw passed in image onto graphics object
g.DrawImage(b, new Point(0, 0)); //???
return returnBitmap;
}
private float CalcAngle(Point TargetPos)
{
Point ZeroPoint = new Point(pictureBox1.Location.X + pictureBox1.Width/2, pictureBox1.Location.Y + pictureBox1.Height/2);
if (TargetPos == ZeroPoint)
{
return 0;
}
double angle;
double deltaX, deltaY;
deltaY = TargetPos.Y - ZeroPoint.Y;
deltaX = TargetPos.X - ZeroPoint.X;
angle = Math.Atan2(deltaY, deltaX) * 180/Math.PI;
return (float)angle;
}
private void timer1_Tick(object sender, EventArgs e)
{
pictureBox1.Image = (Bitmap)backup.Clone();
//Load an image in from a file
Image image = new Bitmap(pictureBox1.Image);
//Set our picture box to that image
pictureBox1.Image = (Bitmap)backup.Clone();
//Store our old image so we can delete it
Image oldImage = pictureBox1.Image;
//Set angle
angle = CalcAngle(new Point(Cursor.Position.X, Cursor.Position.Y - 10));
//Pass in our original image and return a new image rotated X degrees right
pictureBox1.Image = rotateImage((Bitmap)image, angle);
if (oldImage != null)
{
oldImage.Dispose();
image.Dispose();
}
}
지금까지 시도한 코드 스 니펫 중 일부를 첨부하십시오. – Daenarys
회전 알고리즘을 넣었으며 투명성 문제에 대해서는 아직 어떤 코드도 구현하지 않았습니다 (양식에서 한 패널 항목 편집자). – user3506622