Comments (2)
Good grief - this never crossed my mind. Curiously enough I had a support ticket recently for another user who was having difficulties with the ImageBox and giant images. I'd made a "rainy day note" after that to try and do a demo where multiple separate images are drawn as though they were a single image, similar to how things like online maps work. It just didn't twig that I could have done the same thing as you suggest.
Thanks very much for the tip - I will give that a go!
from cyotek.windows.forms.imagebox.
I write a control derived from ImageBox. I would like to share the code here, and hope it could be useful. And hope the new version could be improved. Thanks!
public class PictureBox : ImageBox
{
public const float MaxDrawImageSidePixels = 5000;
protected override void DrawImage(Graphics g)
{
Rectangle dstView = this.GetImageViewPort();
RectangleF srcPortion = this.GetSourceImageRegion();
if (srcPortion.Width <= MaxDrawImageSidePixels && srcPortion.Height <= MaxDrawImageSidePixels)
{
base.DrawImage(g);
//TextRenderer.DrawText(g, srcPortion.ToString(), this.Font, this.ClientRectangle, this.ForeColor, this.BackColor, TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix);
return;
}
InterpolationMode currentInterpolationMode;
PixelOffsetMode currentPixelOffsetMode;
currentInterpolationMode = g.InterpolationMode;
currentPixelOffsetMode = g.PixelOffsetMode;
g.InterpolationMode = this.GetInterpolationMode();
// disable pixel offsets. Thanks to Rotem for the info.
// http://stackoverflow.com/questions/14070311/why-is-graphics-drawimage-cropping-part-of-my-image/14070372#14070372
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
RectangleF rfDst=new RectangleF(0,0,100,100);
RectangleF rfSrc = new RectangleF(0, 0, 100, 100);
try
{
// Animation. Thanks to teamalpha5441 for the contribution
if (this.IsAnimating && !this.DesignMode)
{
ImageAnimator.UpdateFrames(this.Image);
}
int CountOfStepX = (int)Math.Round(srcPortion.Width / MaxDrawImageSidePixels + 0.5);
int CountOfStepY = (int)Math.Round(srcPortion.Height / MaxDrawImageSidePixels + 0.5);
float stepDstX = (int)(dstView.Width / CountOfStepX);
float stepDstY = (int)(dstView.Height / CountOfStepY);
float stepSrcX = (int)(srcPortion.Width / CountOfStepX);
float stepSrcY = (int)(srcPortion.Height / CountOfStepY);
for(int w=0;w< CountOfStepX;w++)
for(int h=0; h<CountOfStepY;h++)
{
rfDst = new RectangleF(dstView.X+ stepDstX*w, dstView.Y + stepDstY * h, stepDstX, stepDstY);
rfSrc= new RectangleF(srcPortion.X+ stepSrcX *w, srcPortion.Y + stepSrcY * h, stepSrcX, stepSrcY);
g.DrawImage(this.Image, rfDst, rfSrc, GraphicsUnit.Pixel);
//Rectangle txtRect = new Rectangle((int)rfDst.X, (int)rfDst.Y, (int)rfDst.Width, (int)rfDst.Height);
//TextRenderer.DrawText(g, rfDst.ToString() + " " + rfSrc.ToString(), this.Font, txtRect, this.ForeColor, this.BackColor, TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix);
}
}
catch (Exception ex)
{
TextRenderer.DrawText(g, ex.Message, this.Font, this.ClientRectangle, this.ForeColor, this.BackColor, TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter | TextFormatFlags.WordBreak | TextFormatFlags.NoPadding | TextFormatFlags.NoPrefix);
}
g.PixelOffsetMode = currentPixelOffsetMode;
g.InterpolationMode = currentInterpolationMode;
}
}
from cyotek.windows.forms.imagebox.
Related Issues (20)
- Integration with Accord.NET.Framework HOT 1
- VirtualDraw and Scale\Transform HOT 2
- Swipe support? HOT 2
- Wrong selection area when maximizing HOT 2
- Creating and Zooming Graphics
- How to determinate a pixel in the imageBox (Mouse click) with total precision HOT 1
- How to get image Point use mouse position? HOT 1
- Unable to Crop image HOT 1
- Add ability for transparent background color to be used
- Image graphics disappear when zooming out HOT 2
- Is this project still maintained? What about the nuget package? HOT 2
- Support. Net 5.0 HOT 2
- Wrong scrolling in CanPan method HOT 4
- How to save viewport as bitmap? HOT 1
- Π‘an't distinguish click and panning event HOT 1
- The image has moire patterns when scale 15% HOT 3
- Use 2 ImageBoxes side by side
- Gap bug with foreground color HOT 1
- There isn't a way to disable scrollbar HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cyotek.windows.forms.imagebox.