System.Drawing and Scaling.

I've been experimenting with graphics and I want to scale image up and down.

I've done this with graphics and scaling transforms and I have a problems. The resuls are beautiful interpolations but that not what I am looking for. In its displays, Photoshop displays pixels, not magnified interpolated contents. As best I can see and guess, in Photoshop when you are looking at an image displayed as 200 percent of its original size, it's look to me as if one pixel is replaced by four identical pixels (two on a side).

Is there a way to do scaling in this manner instead of all the interpolation




Answer this question

System.Drawing and Scaling.

  • Guy Pilk

    Andreas Johansson wrote:

    Spidermans_DarkSide,

    you are always free to reply to any question you want. If the original poster doesn't like it it is up to them to ignore your reply as nobody will touch it as long as it is inside our guidelines.

    If you ignore her and she ignores you we will all be happy.

    Hi,

    Well said.

    Regards,

    S_DS



  • priyananda

     HemeFlasher wrote:
    Please do be kind and please don't answer any of my questions.

    Is that meant for everyone

    Please see (at the top of the list)
    "How to receive the best support for your question"

     

    Hi,

     I believe ReneeC was referring to me due to a problem She has over certain posts.

     I think She feels She has to comment about them, even if it is in a nasty fashion ( it seems ), so watch out....

     It is far easier to ignore posts that you don't find helpful, i.m.h.o.

    She can't even get my screen name right then answers Her own question!! I wouldn't even post a question without making an attempt to solve a problem 1st.

     

     

    Regards,

    S_DS

     



  • Nima_DK

    Please do be kind and please don't answer any of my questions.

    Is that meant for everyone

    Please see (at the top of the list)
    "How to receive the best support for your question"


  • Teo97917

     ReneeC wrote:

     

    Your answers had nothing to with my questions. at all. What it is that I am doing has nothing whatsoever to do with photoshop so your response has to be to the universe of things that I wasn't asking. It's not that DOT NET is not doing enough work, I think its doing too much.

    I know how to use Search. Please do be kind and please don't answer any of my questions.

     One of my links was to the SCALEmode. You were asking about scaling.

    By the way i'm going to say the same then....

     I know how to use Search. Please do be kind and don't answer any of my questions either, i'd rather help someone who doesn't complain in these forums.

     

    Regards,

    S_DS

     



  • Thomas LEBRUN

    JohnWein wrote:
    Doesn't setting System.Drawing.Graphics.InterpolationMode to System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor do what you want

    I am not sure but I know what Renee want't to do is this to a source bitmap

    AABB
    CCDD

    and at level 2 turn it into

    AAAABBBB
    AAAABBBB
    CCCCDDDD
    CCCCDDDD

    Does nearestneighbour do that



  • Can-Ann

     

    Your answers had nothing to with my questions. at all. What it is that I am doing has nothing whatsoever to do with photoshop so your response has to be to the universe of things that I wasn't asking. It's not that DOT NET is not doing enough work, I think its doing too much.

    I know how to use Search. Please do be kind and please don't answer any of my questions.



  • Bill Gates II

    Doesn't setting System.Drawing.Graphics.InterpolationMode to System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor do what you want
  • Ion101

    I was looking for non-interpolative methods for enlarging an image in the fashion that photoship does. Actually it's a matix scalling transform. I didn't see anything qute like I wanted in the matrix classes, so I wote my own.

    Public Function MultImageSize(ByVal Image As Image, ByVal Multiplier As Integer) As Bitmap

    Dim Ibm As Bitmap = Image.Clone

    Dim Obm As New Bitmap(Image.Width * Multiplier, Image.Height * Multiplier)

    Dim Ix As Integer = Image.Width : Dim Iy As Integer = Image.Height

    Dim Ox As Integer = Obm.Width : Dim Oy As Integer = Obm.Height

    Dim Irect As New Rectangle(0, 0, Ix, Iy)

    Dim ibmpData As System.Drawing.Imaging.BitmapData = Ibm.LockBits(Irect, _

    Drawing.Imaging.ImageLockMode.ReadWrite, _

    Drawing.Imaging.PixelFormat.Format32bppArgb)

    '' Get the address of its first scan line

    Dim Iptr As IntPtr = ibmpData.Scan0

    Dim IBytesPerPixel As Integer = ibmpData.Stride / Ix

    ' Prepare an array that will receive all the pixels

    Dim IArraySize As Integer = (Ix * Iy)

    Dim Ipixels(IArraySize - 1) As Integer

    '' Copy the pixels into the array

    Marshal.Copy(Iptr, Ipixels, 0, (IArraySize))

    Ibm.UnlockBits(ibmpData)

    Dim Orect As New Rectangle(0, 0, Ox, Oy)

    Dim ObmpData As System.Drawing.Imaging.BitmapData = Obm.LockBits(Orect, _

    Drawing.Imaging.ImageLockMode.ReadWrite, _

    Drawing.Imaging.PixelFormat.Format32bppArgb)

    '' Get the address of its first scan line

    Dim Optr As IntPtr = ObmpData.Scan0

    Dim OBytesPerPixel As Integer = ObmpData.Stride / Ox

    '' Prepare an array that will receive all the pixels

    Dim Opixels() As Integer = _

    MatrixExpand(Ipixels, Multiplier, Ix, Iy)

    Marshal.Copy(Opixels, 0, Optr, Opixels.Length)

    Obm.UnlockBits(ObmpData)

    Ipixels = Nothing : Opixels = Nothing

    Ibm.Dispose()

    Return Obm

    End Function

    Private Function MatrixExpand(ByVal Iarray As Integer(), ByVal Multiplier As Integer, _

    ByVal ix As Integer, ByVal iy As Integer) As Integer()

    Dim Oarray(((ix * iy) * (Multiplier * Multiplier)) - 1) As Integer

    Static InputrowNum As Integer : Dim OutputRowNum As Integer

    Dim LengthOfOutputRow = ix * Multiplier

    For InputrowNum = 0 To iy - 1

    FillUniqueRows(Oarray, ix, Iarray, InputrowNum, Multiplier, OutputRowNum)

    OutputRowNum += Multiplier

    Next

    For OutputRowNum = 0 To (iy * Multiplier) - 1 Step Multiplier

    CopyRows(Oarray, OutputRowNum, ix, Multiplier)

    Next

    Return Oarray

    End Function

    Private Sub CopyRows(ByRef Oarray() As Integer, ByVal InputrowNum As Integer, _

    ByVal MLength As Integer, ByVal Multiplier As Integer)

    Dim RowstoCopy As Integer = Multiplier - 1 : If RowstoCopy = 0 Then Exit Sub

    Dim oElements = MLength * Multiplier

    Dim MStartIndex As Integer = InputrowNum * oElements

    Dim oDestStartIndex As Integer = MStartIndex

    For z As Integer = 0 To Multiplier - 2

    oDestStartIndex += oElements

    For i As Integer = 0 To (oElements) - 1

    Oarray(oDestStartIndex + i) = Oarray(MStartIndex + i)

    Next

    Next

    End Sub

    Private Sub FillUniqueRows(ByRef Oarray() As Integer, ByVal ElementsInInrow As Integer, _

    ByVal Inarray() As Integer, ByVal InRowNum As Integer, _

    ByVal Multiplier As Integer, ByVal OutputRowNum As Integer)

    Static OutArrayIndex As Integer : OutArrayIndex = 0

    Static InArrayIndex As Integer : InArrayIndex = 0

    Static InstartIndex As Integer : InstartIndex = ElementsInInrow * InRowNum

    Dim YStart As Integer

    YStart = (OutputRowNum * (ElementsInInrow)) * Multiplier

    For X As Integer = 0 To ElementsInInrow - 1

    OutArrayIndex = (X * Multiplier) + YStart

    InArrayIndex = X + InstartIndex

    Oarray(OutArrayIndex) = Inarray(InArrayIndex)

    For Xi As Integer = OutArrayIndex + 1 To (OutArrayIndex + (Multiplier - 1))

    Oarray(Xi) = Inarray(InArrayIndex) ' fill in the master row

    Next

    Next

    End Sub

    Do you see any difference between this and DSSpierman's reponse



  • Richard Morgan

    Spidermans_DarkSide,

    you are always free to reply to any question you want. If the original poster doesn't like it it is up to them to ignore your reply as nobody will touch it as long as it is inside our guidelines.

    If you ignore her and she ignores you we will all be happy.



  • wsalomon

    Hi,

    Not as easy as linear regression eh Only kidding.

     

     I'd look at scaling tranforms based on larger samples of arrays like a 5 x 5 array and scale it to 25 x 25.

    Going the other way i think you'd have to take an average of the colour levels or look at what the main colour shade is based on histograms, not just the RGB and alpha levels.

    You could try automating PhotoShop maybe through API calls but i doubt Photoshop program vendors will tell you their secrets.

    Have you tried the scaling options of putting the image file into different sized pictureBoxes and let Windows do the hard work

     I think there a 3 options in the ScaleMode for doing this.

     I think .Net has less scaleMode options than VB6.

    See these links.>>

     
     
     
     
     
     

     

     

    Regards,

    S_DS

     



  • System.Drawing and Scaling.