none
Trimming a graphic buffer by looking for black pixels around the sides RRS feed

  • Question

  • What I want to consider doing is lets say I have a buffer that starts off with a size of 1000 x 1000. Now lets say my graphics image is 800 pixels wide. If I can have a routine that starts at 1000 and moves in until it hits the first black pixel that I think would be a lot easier to keep track of a final buffer size then having to watch the size anytime I draw through the buffer with all different shapes and sizes. I also think because my graphics is not intense that the speed of looking for pixels would be negligible.

    Just a crazy thought I was kicking around.

    Les

    Tuesday, August 7, 2018 4:53 AM

Answers

  • Hi Les, 

    There shouldn't have been any errors unless we have a difference in VS versions (I'm on 2017).  If you let me know your version or which lines cause errors I can look into it.

    As for division lines etc. that could be handled through additional properties on the class that holds the equation parts (FormulaTerm) and/or through sub classes.  That class already has a Font property so you can just assign the appropriate font to each instance of FormulaTerm when you create it.

    The various special characters can be assigned to the FormulaTerm.Text property.  You could add a property called something like "Place" of an Enum type where the possible Enum values are Numerator or Denominator (or use a IsNumerator Boolean property and draw the term as a denominator if it is false).  Or you could inherit from ForumlaTerm and create classes called NumeratorTerm and DenominatorTerm then draw them in their appropriate place after testing the type.  The exponent could be a Boolean flag that if set, means the term is drawn as an exponent.

    So there are lots of different ways that you can design the class to suit the various requirements needed.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by Les2011 Wednesday, August 8, 2018 6:22 AM
    Wednesday, August 8, 2018 12:52 AM
    Moderator

All replies

  • Hi Les,

    To get the most out of the forum, be sure to include links to your existing threads when they relate to a new one.  In this case, I know what you mean by "buffer" and can understand the question about measurement only because I've been following your development.  Other users would most likely be confused.  Including a link that shows the code you are using would be helpful. :)

    To answer the question, I'm not sure that it would be easier and I'm sure it would be less efficient.  You'd first have to determine which vertical line of pixels contained the last non-white one.  That would mean scanning vertically from the right and could become time consuming quickly with the GetPixel method.  This is a very inefficient method and is generally only useful for an occasional call here and there.  When you need to test a lot of pixels (consider that only two passes is 2000 calls), you'll want to go a different route that requires a lot more code and calculation (LockBits method and marshaling bytes from the resulting BitMapData, then analyzing the individual bytes of each color of each pixel).  In the end, it is not easier than keeping track of the longest thing you draw.

    If you go back to the little class based example I gave you, you'll see where each drawing element keeps track of its own size.  With code like that it is simple to execute a LINQ statement over the collection to get the element with the longest width.  Then you aren't really tracking the longest one as you go... you are simply remembering the size of each element when it gets measured and then later finding the longest one when needed.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    Tuesday, August 7, 2018 11:35 AM
    Moderator
  • Hi Reed,

    Yes I understand the issue with the redundancy.  I looked at the code, but did not study it thoroughly yet from the previous example you provided.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/414a7998-1e92-4b1d-885a-a83ad5702bcb/adjusting-size-of-a-graphics-buffer-addendum?forum=vbgeneral

    I did try it but it popped up a lot of errors which at this point is a bit confusing for me to solve.  When I look at the code Reed I take it that it will place the exponents in the proper locations and I like how you coded things. As always it gives me more things to understand <S>.  BTW how will this coding technique allow me to draw division lines square root symbols and summation symbols etc since all of them will be designed by me.  I cant use the fonts that do exist since it will all be different?  Just curious.  I will keep you posted as I try to play with your code snippet.

    Thanks

    Tuesday, August 7, 2018 7:56 PM
  • Hi Les, 

    There shouldn't have been any errors unless we have a difference in VS versions (I'm on 2017).  If you let me know your version or which lines cause errors I can look into it.

    As for division lines etc. that could be handled through additional properties on the class that holds the equation parts (FormulaTerm) and/or through sub classes.  That class already has a Font property so you can just assign the appropriate font to each instance of FormulaTerm when you create it.

    The various special characters can be assigned to the FormulaTerm.Text property.  You could add a property called something like "Place" of an Enum type where the possible Enum values are Numerator or Denominator (or use a IsNumerator Boolean property and draw the term as a denominator if it is false).  Or you could inherit from ForumlaTerm and create classes called NumeratorTerm and DenominatorTerm then draw them in their appropriate place after testing the type.  The exponent could be a Boolean flag that if set, means the term is drawn as an exponent.

    So there are lots of different ways that you can design the class to suit the various requirements needed.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    • Marked as answer by Les2011 Wednesday, August 8, 2018 6:22 AM
    Wednesday, August 8, 2018 12:52 AM
    Moderator
  • Hi Reed,

    You were right I was running 2010 and not 2017.  In 2017 your code works fine.  I purchased a book on vb 2017 that I see I need to get familiar with <S>.  I am going to study the IDE and etc and afterwards start working in 2017.  Will mark this thread answered and will get back to my coding after I familiarize myself with 2017.

    Thanks Reed

    Les

    Wednesday, August 8, 2018 6:22 AM
  • Hi Reed,

    You were right I was running 2010 and not 2017.  In 2017 your code works fine.  I purchased a book on vb 2017 that I see I need to get familiar with <S>.  I am going to study the IDE and etc and afterwards start working in 2017.  Will mark this thread answered and will get back to my coding after I familiarize myself with 2017.

    Thanks Reed

    Les


    Sounds good.  Everything you are used to in 2010 should still apply, there will just be some new features that you can take advantage of.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Wednesday, August 8, 2018 2:16 PM
    Moderator