NextPVR Forums
  • ______
  • Home
  • New Posts
  • Wiki
  • Members
  • Help
  • Search
  • Register
  • Login
  • Home
  • Wiki
  • Members
  • Help
  • Search
NextPVR Forums Public Developers v
« Previous 1 … 70 71 72 73 74 … 93 Next »
who is good at maths?

 
  • 0 Vote(s) - 0 Average
who is good at maths?
smeghead
Offline

Senior Member

Posts: 300
Threads: 23
Joined: Jan 2005
#21
2005-07-07, 05:10 PM
I think you've got it. But, the screen size is "almost" fixed. If you set the screen size to the same aspect ratio as the image you will keep the aspect ratio correct for zoom operations. You only need calculate it once. So, in your example the screen size is 720 * 480 , the image is 360 * 240 so you use 720 * 480 as the actual screen size - bad example let's try another:
Screen size 720 * 480. image dimensions 340 * 240. You would do the maths once per image and adjust your screen size to 680 * 480. i.e. the maximum screen size that maintains the correct aspect ratio. This will then work for all zoom operations, panning etc. Use this as the "destination" rectangle.

In your previous post you are correct, I did get the wrong params on DrawImage. Use the one you suggest, instead of producing a SourceImage rectangle variable. Essentially it does exactly the same thing.

Does this make sense yet?
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#22
2005-07-07, 05:39 PM
yeah it makes sense, i just know if i write the code im going to get it wrong again, i keep making the same mistakes, i need a fresh set of eyes.

the aspect ratio should always been maintained once it has been first setup, which i do before i create teh ImageHelper (the class which holds all the widths etc, post before).

i just need the formula/code to get the src rectangle of what i want to draw (this is what i keep getting wrong). ill worry about things like if srcwidth<bounds.width later (ie dont waste time drawing black space on the side, im not sure if that would slow it down, but i may aswell check for it).

so in the code im using
Bounds = 720x480 (for most skins)
g.drawImage(image, Bounds, srcx????, srcy????, srcwidth????,srcheight???,pixels, attributes)
this would allow for negative values for srcx if the width is less than the screen width, etc (which ill fix once i get the basics working).
so yeah just need a function/formula to get those src values (its one of those things that has got me stumped, but as soon as i see the solution, im going to say "dah!"....)
smeghead
Offline

Senior Member

Posts: 300
Threads: 23
Joined: Jan 2005
#23
2005-07-07, 07:33 PM
reven: I'm on it now, give me an hour or so.
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#24
2005-07-07, 07:35 PM
sweet, thanks smeghead.
Heyt
Offline

Member

Posts: 106
Threads: 9
Joined: Jan 2005
#25
2005-07-07, 08:25 PM (This post was last modified: 2005-07-07, 08:55 PM by Heyt.)
Just to make clear what these values are

Quote: double leftpos = //will be the difference between 0,0 coordinate and the left most position on the screen (positive value)
double toppos = //will be the difference between 0,0 coordinate and the top most position on the screen (positive value)

As i understood you initialy shrink the images so they are completly visible and display them centered. But this means the top/left most position of the image is not the top/left most position of the screen and as i understood you set the coordinate point (0,0) to the left/top edge of the image.
But what i need is the difference between these two positions (as a positive value).
So for example you have a screen size of 720x576 and an image size of 600x400 then the value for leftpos would be 60 and for toppos 88. For this example leftoff and topoff will be in deed both 0, but if you have an already zoomed image which exeeds the visible screen size they are not 0 and also needed only then.

I added a pdf were i caluculated two realistic zooms with the code on a pal screen.

OK now i have the file it is here PDF

PS.: By the way the file and stuff is more for info because i've seen you now use a completly other approach to solve the problem, my code is based on your first try.
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#26
2005-07-07, 08:36 PM
Heyt Wrote:Just to make clear what these values are



As i understood you initialy shrink the images so they are completly visible and display them centered. But this means the top/left most position of the image is not the top/left most position of the screen and as i understood you set the coordinate point (0,0) to the left/top edge of the image.
But what i need is the difference between these two positions (as a positive value).
So for example you have a screen size of 720x576 and an image size of 600x400 then the value for leftpos would be 60 and for toppos 88. For this example leftoff and topoff will be in deed both 0, but if you have an already zoomed image which exeeds the visible screen size they are not 0 and also needed only then.

I added a pdf were i caluculated two realistic zooms with the code on a pal screen.
so that would just be
double leftpos = current.X;
if(leftpos <0)
leftpos = leftpos * -1;
double toppos = current.Y;
if(toppos < 0)
toppos = toppos *-1;
?


(ive got two bits of code trying to do this now, and both are very different approaches..., oh plus 3 if you include my attempt..... getting confusing.. Smile)
smeghead
Offline

Senior Member

Posts: 300
Threads: 23
Joined: Jan 2005
#27
2005-07-07, 08:40 PM
Here we go:

public class Class1
{
//Declare Global Variables
Image MyJPEGPicture;
int CentreX, CentreY;
int ImageWidth, ImageHeight;
// the destination screen size
int ScreenWidth = 720;
int ScreenHeight = 480;
// you can supply an offset position in the destination screen
int ScreenXOffset = 0;
int ScreenYOffset = 0;
double Zoom = 1.0;

public Class1(string jpegfilename)
{
// Initialisation
Zoom = 1.0;
MyJPEGPicture = Image.FromFile(jpegfilename);
// Create rectangle for displaying original image.
ImageWidth = MyJPEGPicture.Width;
ImageHeight = MyJPEGPicture.Height;
CentreX = ImageWidth / 2;
CentreY = ImageHeight / 2;
}

private void MyDrawImage( System.Drawing.Image MainImage, System.Drawing.Imaging.ImageAttributes imageAttributes )
{
double standard_screen_ratio = ScreenWidth / ScreenHeight;
// Calculate the screen rectangle to put the image into based on aspect ratio of
double image_ratio = ImageWidth / ImageHeight;
int usable_screen_width = ScreenWidth;
int usable_screen_height = ScreenHeight;
double srcwidth = ImageWidth / Zoom;
double srcheight = ImageHeight / Zoom;

if ( Math.Equals(Zoom,1.0) )
{
if ( image_ratio > standard_screen_ratio )
{
// width is predominant so scale height down
usable_screen_width = ScreenWidth;
usable_screen_height = (ImageHeight * ScreenWidth) / ImageWidth;
}
else
{
// height is predominant so scale width down
usable_screen_width = (ImageWidth * ScreenHeight) / ImageHeight;
usable_screen_height = ScreenHeight;
}
}
else
{
// We needn't alter the screen size but need to update srcwidth and srcheight to fill screen
// whilst maintaining image ratio
if ( image_ratio > standard_screen_ratio )
{
// width is predominant so scale up height to take from source image
srcheight = srcheight * standard_screen_ratio;
}
else
{
// height is predominant so scale up width to take from source image
srcwidth = srcwidth * standard_screen_ratio;
}
}

// Make local copies for manipulation
double CentreX_Local = CentreX;
double CentreY_Local = CentreY;
// if the right edge of the source rectangle is outside the source image right edge then bring it back.
if ( CentreX_Local + (srcwidth/2) > ImageWidth )
{
CentreX_Local = ImageWidth - (srcwidth/2);
}
// if the left edge of the source rectangle is outside the source image left edge then bring it back.
if ( CentreX_Local - (srcwidth/2) < 0 )
{
CentreX_Local = ImageWidth + (srcwidth/2);
}

// if the bottom edge of the source rectangle is outside the source image bottom edge then bring it back.
if ( CentreY_Local + (srcheight/2) > ImageHeight )
{
CentreY_Local = ImageHeight - (srcheight/2);
}

// if the top edge of the source rectangle is outside the source image top edge then bring it back.
if ( CentreY_Local - (srcheight/2) < 0 )
{
CentreY_Local = ImageHeight + (srcheight/2);
}

int srcx = (int)Math.Round(CentreX_Local - (srcwidth / 2));
int srcy = (int)Math.Round(CentreY_Local - (srcheight / 2));

// So, now we have all our variables
System.Drawing.Rectangle ScreenImageRect = new System.Drawing.Rectangle(ScreenXOffset, ScreenYOffset,ScreenXOffset + usable_screen_width, ScreenYOffset + usable_screen_height );
Graphics.FromImage(MainImage).drawImage(MyJPEGPicture, ScreenImageRect, srcx, srcy, srcwidth, srcheight, GraphicsUnit.Pixel, imageAttributes);
}

public void ZoomIn()
{
Zoom = Zoom * 2.0;
if ( Zoom > 64.0 )
{
Zoom = 64.0; // just to bound the value
}
}

public void ZoomOut()
{
Zoom = Zoom / 2.0;
if ( Zoom < 1.0 )
{
Zoom = 1.0; // just to bound the value
}
}

public void MoveLeft()
{
CentreX = CentreX - 10;
}
public void MoveRight()
{
CentreX = CentreX + 10;
}
public void MoveDown()
{
CentreY = CentreY + 10;
}
public void MoveUp()
{
CentreY = CentreY - 10;
}


}
smeghead
Offline

Senior Member

Posts: 300
Threads: 23
Joined: Jan 2005
#28
2005-07-07, 09:00 PM
Oh dear, time to eat humble pie. Change the int to double.

I'm still testing this but it seems to work so far
Heyt
Offline

Member

Posts: 106
Threads: 9
Joined: Jan 2005
#29
2005-07-07, 09:03 PM (This post was last modified: 2005-07-07, 09:06 PM by Heyt.)
Quote:so that would just be
double leftpos = current.X;
if(leftpos <0)
leftpos = leftpos * -1;
double toppos = current.Y;
if(toppos < 0)
toppos = toppos *-1;
no you just need to set leftpos and toppos once and this is when you have zoomed the image that way that it is fully visible and centered. Both values will never be smaller than 0 this way. Afterwards you don't need to change these two any more. So you just need the lines
double leftpos = current.X;
double toppos = current.Y;
Or just look at the examples in the PDF i just added to my previous post (had some problems with it).

Quote:ive got two bits of code trying to do this now, and both are very different approaches..., oh plus 3 if you include my attempt..... getting confusing..
Yes i know, mine is just for zooming in and the other one can do much more, but decide yourself
reven
Offline

Posting Freak

Posts: 5,782
Threads: 396
Joined: Sep 2004
#30
2005-07-07, 09:15 PM
thanks guys, ill try it out in a couple of hours (watching a movie, so pvr is busy).
« Next Oldest | Next Newest »

Users browsing this thread: 1 Guest(s)

Pages (4): « Previous 1 2 3 4 Next »


Possibly Related Threads…
Thread Author Replies Views Last Post
  What's a good Open Source VB.net plugin that I could browse? zehd 0 1,201 2007-01-30, 02:00 AM
Last Post: zehd
  Anyone recommend a good C# book? bgowland 9 3,694 2005-01-03, 07:32 PM
Last Post: bgowland

  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Designed by D&D, modified by NextPVR - Powered by MyBB

Linear Mode
Threaded Mode