Created
March 6, 2017 14:53
-
-
Save s0ren/01f97998ba2d20ce8d59a41248c54328 to your computer and use it in GitHub Desktop.
Morten Billedviser Problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
// inspireret af http://www.c-sharpcorner.com/forums/faster-picturebox-loading-or-alternatives | |
// og https://msdn.microsoft.com/en-us/library/k0fsyd4e(v=vs.110).aspx | |
// | |
namespace MortensBilledViserproblem | |
{ | |
public partial class Form1: Form | |
{ | |
Bitmap bitmap, img; | |
Graphics bmpgraphic; | |
public Form1() | |
{ | |
InitializeComponent(); | |
backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted); | |
} | |
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) | |
{ | |
if (img != null) | |
{ | |
img.Dispose(); | |
} | |
if (bitmap != null) | |
{ | |
bitmap.Dispose(); | |
} | |
if (bmpgraphic != null) | |
{ | |
bmpgraphic.Dispose(); | |
} | |
bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height, System.Drawing.Imaging.PixelFormat.Format64bppPArgb); // Where w is your width for all your images! Also the height. | |
bmpgraphic = Graphics.FromImage(bitmap); // This is the connection between the Graphic and the Bitmap! Very important | |
bmpgraphic.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy; | |
bmpgraphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.GammaCorrected; | |
bmpgraphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; | |
//for (i = 0; i < imagecount; i++) | |
//{ | |
//set actual image | |
img = new Bitmap("drone.jpg"); | |
bmpgraphic.DrawImage( | |
img, | |
new RectangleF(0, 0, pictureBox1.Width, pictureBox1.Height), | |
new RectangleF(0, 0, img.Width, img.Height), | |
GraphicsUnit.Pixel ); | |
//} | |
} | |
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) | |
{ | |
pictureBox1.Image = bitmap; | |
} | |
private void pictureBox1_Click(object sender, EventArgs e) | |
{ | |
backgroundWorker1.RunWorkerAsync(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ikk @s0ren