ParadoX | Hm je n'y arrive pas
L'ennui, c'est que je veux extraire un rectangle d'un bitmap avec des coordonnées précises (en Cm, malheureusement !), et faire afficher cet extrait de facon agrandie dans un viewerPanel.
J'ai ceci pour le moment, ca marche, mais ca m'affiche l'image entiere (avec le bon ratio) dans le viewerPanel:
Code :
- private void GenerateThumbnail(string path, int selectedPage)
- {
- //int dpi = 72;
- using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
- {
- byte[] buffer = new byte[file.Length];
- file.Read(buffer, 0, buffer.Length);
- document = new Document(new BinaryReader(new MemoryStream(buffer)));
- }
- Page page = document.Pages[selectedPage];
- bitmap = new Bitmap(
- (int)(page.Width),
- (int)(page.Height));
- Graphics graphics = Graphics.FromImage(bitmap);
- page.Draw(graphics);
- }
|
Puis:
Code :
- private void viewerPanel_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
- {
- e.Graphics.Clear(Color.White);
- if (null != bitmap)
- {
- float ratio = (float)bitmap.Width / (float)bitmap.Height;
- float displayWidth, displayHeight;
- if (ratio * viewerPanel.Height > viewerPanel.Width)
- {
- displayWidth = viewerPanel.Width - 10;
- displayHeight = displayWidth / ratio;
- }
- else
- {
- displayHeight = viewerPanel.Height - 10;
- displayWidth = displayHeight * ratio;
- }
- float x = (viewerPanel.Width - displayWidth) / 2;
- float y = (viewerPanel.Height - displayHeight) / 2;
- System.Drawing.Rectangle rect = new System.Drawing.Rectangle(10, 10, 150, 100);
- e.Graphics.DrawImage(bitmap, x, y, displayWidth, displayHeight);
- e.Graphics.DrawRectangle(new Pen(Color.Gray), x, y, displayWidth, displayHeight);
- }
- }
|
J'aimerais, dans mon rectangle Rect, faire afficher un rectanlg extrait du BMP. ![:/ :/](https://forum-images.hardware.fr/icones/ohwell.gif) ---------------
Pier noir la mèr - La chanson par HFR Band - Topic TrueCrypt
|