コード例 #1
0
    public byte[] Render(DesignPattern pattern, System.Drawing.Bitmap qrCode1, System.Drawing.Bitmap qrCode2 = null, System.Drawing.Bitmap qrCode3 = null, System.Drawing.Bitmap qrCode4 = null)
    {
        var patternBitmap = pattern.GetBitmap();

        patternBitmap.Background(System.Drawing.Color.FromArgb(255, 255, 255));
        var scaledImage   = Scaler.ScaleImage(patternBitmap, 4, null);
        var scaledTexture = scaledImage.ToTexture2D(null);
        var preview       = Previews.AllPreviews[pattern.Type];

        preview.SetTexture(scaledTexture);
        preview.ResetPosition();
        Text.text = pattern.Name;
        if (qrCode2 != null)
        {
            OneQR.SetActive(false);
            FourQR.SetActive(true);

            preview.Camera.Render();
            var img1 = RenderImage(preview.Camera.targetTexture);
            TopLeftPreviewImage.texture = img1;
            var qr1 = qrCode1.ToTexture2D(null);
            qr1.filterMode             = FilterMode.Point;
            TopLeftQRCodeImage.texture = qr1;

            preview.Move(90f, 0f);
            preview.Camera.Render();

            var img2 = RenderImage(preview.Camera.targetTexture);
            TopRightPreviewImage.texture = img2;
            var qr2 = qrCode2.ToTexture2D(null);
            qr2.filterMode = FilterMode.Point;
            TopRightQRCodeImage.texture = qr2;

            preview.Move(90f, 0f);
            preview.Camera.Render();

            var img3 = RenderImage(preview.Camera.targetTexture);
            BottomLeftPreviewImage.texture = img3;
            var qr3 = qrCode3.ToTexture2D(null);
            qr3.filterMode = FilterMode.Point;
            BottomLeftQRCodeImage.texture = qr3;

            preview.Move(90f, 0f);
            preview.Camera.Render();

            var img4 = RenderImage(preview.Camera.targetTexture);
            BottomRightPreviewImage.texture = img4;
            var qr4 = qrCode4.ToTexture2D(null);
            qr4.filterMode = FilterMode.Point;
            BottomRightQRCodeImage.texture = qr4;

            Camera.Render();

            GameObject.DestroyImmediate(img1);
            GameObject.DestroyImmediate(qr1);
            GameObject.DestroyImmediate(img2);
            GameObject.DestroyImmediate(qr2);
            GameObject.DestroyImmediate(img3);
            GameObject.DestroyImmediate(qr3);
            GameObject.DestroyImmediate(img4);
            GameObject.DestroyImmediate(qr4);
        }
        else
        {
            OneQR.SetActive(true);
            FourQR.SetActive(false);

            preview.ResetPosition();
            preview.Camera.Render();
            var img1 = RenderImage(preview.Camera.targetTexture);
            BigLeftImage.texture = img1;
            var qr1 = qrCode1.ToTexture2D(null);
            qr1.filterMode      = FilterMode.Point;
            QRCodeImage.texture = qr1;

            Camera.Render();
            GameObject.DestroyImmediate(img1);
            GameObject.DestroyImmediate(qr1);
        }
        GameObject.DestroyImmediate(scaledTexture);
        scaledImage.Dispose();
        patternBitmap.Dispose();
        var result = RenderImage(Camera.targetTexture);

        return(result.EncodeToPNG());
    }
コード例 #2
0
    public byte[] Render(DesignPattern pattern, TextureBitmap qrCode1, TextureBitmap qrCode2 = null, TextureBitmap qrCode3 = null, TextureBitmap qrCode4 = null)
    {
        var patternBitmap = pattern.GetBitmap();

        var scaledImage = new TextureBitmap(pattern.Width * 4, pattern.Height * 4);

        int[] src    = patternBitmap.ConvertToInt();
        int[] target = new int[scaledImage.Width * scaledImage.Height];
        Scaler.ScaleImage(4, src, target, patternBitmap.Width, patternBitmap.Height, new xBRZNet.ScalerCfg(), 0, int.MaxValue);
        scaledImage.FromInt(target);
        scaledImage.Apply();

        var scaledTexture = scaledImage.Texture;
        var preview       = Previews.AllPreviews[pattern.Type];

        preview.SetTexture(scaledTexture);
        preview.ResetPosition();
        Text.text = pattern.Name;
        if (qrCode2 != null)
        {
            OneQR.SetActive(false);
            FourQR.SetActive(true);

            preview.Camera.Render();
            var img1 = RenderImage(preview.Camera.targetTexture);
            TopLeftPreviewImage.texture = img1;
            var qr1 = qrCode1.Texture;
            qr1.filterMode             = FilterMode.Point;
            TopLeftQRCodeImage.texture = qr1;

            preview.Move(90f, 0f);
            preview.Camera.Render();

            var img2 = RenderImage(preview.Camera.targetTexture);
            TopRightPreviewImage.texture = img2;
            var qr2 = qrCode2.Texture;
            qr2.filterMode = FilterMode.Point;
            TopRightQRCodeImage.texture = qr2;

            preview.Move(90f, 0f);
            preview.Camera.Render();

            var img3 = RenderImage(preview.Camera.targetTexture);
            BottomLeftPreviewImage.texture = img3;
            var qr3 = qrCode3.Texture;
            qr3.filterMode = FilterMode.Point;
            BottomLeftQRCodeImage.texture = qr3;

            preview.Move(90f, 0f);
            preview.Camera.Render();

            var img4 = RenderImage(preview.Camera.targetTexture);
            BottomRightPreviewImage.texture = img4;
            var qr4 = qrCode4.Texture;
            qr4.filterMode = FilterMode.Point;
            BottomRightQRCodeImage.texture = qr4;

            Camera.Render();

            GameObject.Destroy(img1);
            GameObject.Destroy(qr1);
            GameObject.Destroy(img2);
            GameObject.Destroy(qr2);
            GameObject.Destroy(img3);
            GameObject.Destroy(qr3);
            GameObject.Destroy(img4);
            GameObject.Destroy(qr4);
        }
        else
        {
            OneQR.SetActive(true);
            FourQR.SetActive(false);

            preview.ResetPosition();
            preview.Camera.Render();
            var img1 = RenderImage(preview.Camera.targetTexture);
            BigLeftImage.texture = img1;
            var qr1 = qrCode1.Texture;
            qr1.filterMode      = FilterMode.Point;
            QRCodeImage.texture = qr1;

            Camera.Render();
            GameObject.DestroyImmediate(img1);
            GameObject.DestroyImmediate(qr1);
        }
        GameObject.DestroyImmediate(scaledTexture);
        scaledImage.Dispose();
        patternBitmap.Dispose();
        var result = RenderImage(Camera.targetTexture);

        return(result.EncodeToPNG());
    }
コード例 #3
0
ファイル: ImageUtil.cs プロジェクト: yanisdreemurr/NHSE
 public static Bitmap GetImage(this DesignPattern bg)
 {
     return(GetBitmap(bg.GetBitmap(), DesignPattern.Width, DesignPattern.Height));
 }
コード例 #4
0
    public void ShowDesign(DesignServer.Pattern pattern, System.Action confirm)
    {
        if (confirm == null && Cancel == null && Confirm == null && ConfirmImport == null)
        {
            return;
        }
        // we are coming from items
        if (confirm == null)
        {
            SelectedPattern = pattern;
            CancelPop.PopOut();
        }
        if (CurrentPreview != null)
        {
            CurrentPreview.Dispose();
            CurrentPreview = null;
        }
        if (CurrentUpscaledPreview != null)
        {
            CurrentUpscaledPreview.Dispose();
            CurrentUpscaledPreview = null;
        }

        this.Pattern = pattern;
        this.Confirm = confirm;
        this.DesignName.Open();
        this.DesignName.Text  = Pattern.Name;
        this.CreatorName.text = Pattern.Creator;
        var t = (DesignPattern.TypeEnum)Pattern.Type;

        try
        {
            var acnhFileFormat = new ACNHFileFormat(pattern.Bytes);
            if (acnhFileFormat.IsPro)
            {
                DesignPattern = new ProDesignPattern();
                DesignPattern.CopyFrom(acnhFileFormat);
            }
            else
            {
                DesignPattern = new SimpleDesignPattern();
                DesignPattern.CopyFrom(acnhFileFormat);
            }
            CurrentPreview = DesignPattern.GetBitmap();
            CurrentPreview.Apply();
            CurrentPreview.Texture.filterMode = FilterMode.Point;
            CurrentPreview.Texture.wrapMode   = TextureWrapMode.Clamp;

            CurrentUpscaledPreview = new TextureBitmap(CurrentPreview.Width * 4, CurrentPreview.Height * 4);

            int[] src    = CurrentPreview.ConvertToInt();
            int[] target = new int[CurrentUpscaledPreview.Width * CurrentUpscaledPreview.Height];
            var   scaler = new xBRZScaler();
            scaler.ScaleImage(4, src, target, CurrentPreview.Width, CurrentPreview.Height, new xBRZNet.ScalerCfg(), 0, int.MaxValue);
            CurrentUpscaledPreview.FromInt(target);
            CurrentUpscaledPreview.Apply();

            Previews.AllPreviews[DesignPattern.Type].SetTexture(CurrentUpscaledPreview.Texture);
            Previews.AllPreviews[DesignPattern.Type].Render();
            PatternPreview.texture = CurrentPreview.Texture;
            DesignPreview.texture  = Previews.AllPreviews[DesignPattern.Type].Camera.targetTexture;

            this.DesignType.text = DesignPatternInformation.Types[t].Name;
            this.DesignCode.text = "DE-" + pattern.Code;
        }
        catch (System.Exception e)
        {
        }
        StartCoroutine(ShowDesignCoroutine());
    }