2016-07-08 4 views
-1

좋은 하루두 개의 그림 상자를 오버레이하는 방법 C#하지만 배경에있는 그림 상자를 볼 수 있습니다.

제목이 정확한지 잘 모릅니다. 나쁜 영어에 대해 죄송합니다

아래 이미지를 얻으려면 C# inoder를 사용하여 두 개의 그림 상자를 오버레이하고 런타임에 상단 그림 상자의 불투명도를 변경하는 방법.

내가 달성해야하는 것은 이와 비슷한 것입니다. 나는 두 개의 이미지를 가지고 내가 그들에게

첫 번째 이미지 오버레이해야합니다 enter image description here

을하고 난의 텍스트로 두 번째 이미지를 가지고 : 이미지에 또 다른 텍스트입니다. 텍스트의 위치가 첫 번째 이미지의 텍스트 위치보다 낮습니다 (아직 평판이 10 개이기 때문에 두 개 이상의 이미지를 업로드 할 수 없습니다.)

아래 이미지이지만 두개의 PictureBox를 사용

본 최초 한 다음 제 PictureBox를 두 화상의 출력 순서 불투명도를 변경할 수 난 자바를 사용하여 출력 화상을 생성 enter image description here

. 나는 C#을 사용하여 jar 파일을 실행할 수 있다는 것을 알고있다. 사용자는 런타임에 불투명도를 변경해야했습니다. 그래서 내가 어떻게 할 수 있니?

난 (내측)

BufferedImage의 biInner = ImageIO.read 사용 자바 코드; BufferedImage biOutter = ImageIO.read (outter);

System.out.println(biInner); 
    System.out.println(biOutter); 

    Graphics2D g = biOutter.createGraphics(); 
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); 
    int x = (biOutter.getWidth() - biInner.getWidth())/2; 
    int y = (biOutter.getHeight() - biInner.getHeight())/2; 
    System.out.println(x + "x" + y); 
    g.drawImage(biInner, x, y, null); 
    g.dispose(); 

    ImageIO.write(biOutter, "PNG", new File(output)); 

내 질문이 이해되기를 바랍니다. (0.5) 당신은 그냥 샘플을 이동 여기에 당신에게

+0

샘플 https://raviranjankr.wordpress.com/2011/05/25/change-opacity-of -image-in-c/ –

+0

아플 시도하십시오. 고맙습니다. – askquestionzero

+0

선생님이 게시 한 링크에 코드를 보았습니다. 그리고 같은 크기의 그림 상자를 그 위에 놓습니다. 그러나 그림 상자에는 다른 이미지가 있습니다. 그런 다음 프로그램을 실행하려고했습니다. 하지만 아래 그림 상자를 볼 수 없습니다. 나는 상단에있는 picturebox의 투명도를 변경했지만 아래 이미지는 볼 수 없습니다. 나는 그것을 어떻게 얻을 수 있는가? 고맙습니다. – askquestionzero

답변

0

감사합니다,하지만 blueBox은 투명 :

public sealed partial class Form1 : Form 
    { 
    private readonly Bitmap m_BlueBox; 
    private readonly Bitmap m_YellowBox; 

    public Form1() 
    { 
     InitializeComponent(); 
     DoubleBuffered = true; 
     m_YellowBox = CreateBox(Color.Yellow); 
     m_BlueBox = CreateBox(Color.Blue); 
     m_BlueBox = ChangeOpacity(m_BlueBox, 0.5f); 
    } 

    public static Bitmap ChangeOpacity(Image img, float opacityvalue) 
    { 
     var bmp = new Bitmap(img.Width, img.Height); 
     using (var graphics = Graphics.FromImage(bmp)) 
     { 
     var colormatrix = new ColorMatrix(); 
     colormatrix.Matrix33 = opacityvalue; 
     var imgAttribute = new ImageAttributes(); 
     imgAttribute.SetColorMatrix(colormatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); 
     graphics.DrawImage(img, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, img.Width, img.Height, 
      GraphicsUnit.Pixel, imgAttribute); 
     } 
     return bmp; 
    } 

    private static Bitmap CreateBox(Color color) 
    { 
     var bmp = new Bitmap(200, 200); 
     for (var x = 0; x < bmp.Width; x++) 
     { 
     for (var y = 0; y < bmp.Height; y++) 
     { 
      bmp.SetPixel(x, y, color); 
     } 
     } 
     return bmp; 
    } 

    private void Form1_Paint(object sender, PaintEventArgs e) 
    { 
     e.Graphics.DrawImage(m_YellowBox, new Point(10, 10)); 
     e.Graphics.DrawImage(m_BlueBox, new Point(70, 70)); 
    } 
    } 
관련 문제