0

Задача состоит в том, чтобы изменять градус поворота и масштаб изображения в Windows Forms с помощью TrackBar'a. С поворотом разобрался, но вот с масштабом все никак.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp5
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        private float Ang = 0;
        private float Ang1 = 0;
        Bitmap g = new Bitmap(Imame.Value);

        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.TranslateTransform(g.Width / 2, g.Height / 2);
            e.Graphics.RotateTransform(Ang);
            e.Graphics.DrawImage(g, new Point(-g.Width / 2, -g.Height / 2));
        }

        private void ScaleTransformFloat(PaintEventArgs e)
        {
            e.Graphics.ScaleTransform(Ang1, 1.0F);
            e.Graphics.DrawImage(g, new Point(-g.Width / 2, -g.Height / 2));
        }


        private void numericUpDown1_ValueChanged(object sender, EventArgs e)
        {
            Ang = (float)numericUpDown1.Value;
            Invalidate();
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            Ang1 = (float)trackBar1.Value;
            Invalidate();
        }
    }
}
4
  • В смысле не выдерживает?
    – axmed2004
    7 дек 2019 в 20:20
  • @axmed2004 да я просто имел ввиду, что вылетает ошибка, при попытке загрузить изображения. 7 дек 2019 в 20:35
  • Будет лучше если вы приведете текст ошибки
    – axmed2004
    7 дек 2019 в 20:41
  • @axmed2004 Как-то так ссылка 7 дек 2019 в 21:12

1 ответ 1

0

Можете попробовать после каждого вызова события заново переопределять Bitmap.

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.