PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
how to assign a scaled bitmap into another bitmap(
Forums
Newsgroups
Microsoft DotNet
Microsoft Dot NET Compact Framework
how to assign a scaled bitmap into another bitmap(
![]() |
how to assign a scaled bitmap into another bitmap( |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Sir,
I want to assign a scaled bitmap into another bit map how to do it.i have got a.net framework function which is working fime and i need an alternative for it to make it working for .net compactframework. ************************************************************ scaledImg = new Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); ************************************************************ How can this be done. regards Naveem |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Is this what you want?
Dim b As New Bitmap(x, y) Dim g As Graphics = Graphics.FromImage(b) g.DrawImage(AnotherBitmap, destinationRectangle, SourceRectangle, GraphicsUnit.Pixel) "Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message news 613F3FA-A570-4EFB-9BE6-45E8AFBBCF9D@microsoft.com...> Sir, > > I want to assign a scaled bitmap into another bit map > how to do it.i have got a.net framework function which is working fime and > i > need an alternative for it to make it working for .net compactframework. > ************************************************************ > scaledImg = new > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > > ************************************************************ > > How can this be done. > > regards > > Naveem |
|
|
|
#3 |
|
Guest
Posts: n/a
|
No this is not the thing i want, i feel your are not able to get what i am
really asking for. i have a function were image is scaled in .net frameworkthat function is written as this ********************************************************** were scale is 1.0; scale = value; Bitmap scaledImg = new Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); convertToGrayScale(); ********************************************************** Now i want to write this function in comapct frame work . as from here the value of width and height goes to convertto grayscale function which is like this ************************************************************ protected void convertToGrayScale() { Color col; int gray; for (int l = 0; l<scaledImg.Width; l++) for (int c = 0; c<scaledImg.Height; c++) { col = scaledImg.GetPixel(l,c); gray = (int)(0.32f * col.R + 0.5f * col.G + 0.18f* col.B); scaledImg.SetPixel(l,c,Color.FromArgb(gray, gray, gray)); } } *************************************************************** if i am passing like this in compactframework ********************************************************** Bitmap scaledImg = new Bitmap(img); ********************************************************* the values passing to convert to gray function are wrong. so i hardly get correct results. So please teelme alternative for this a. Regards Naveen "Joseph Byrns" wrote: > Is this what you want? > > > > Dim b As New Bitmap(x, y) > > Dim g As Graphics = Graphics.FromImage(b) > > g.DrawImage(AnotherBitmap, destinationRectangle, SourceRectangle, > GraphicsUnit.Pixel) > > > > "Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message > news 613F3FA-A570-4EFB-9BE6-45E8AFBBCF9D@microsoft.com...> > Sir, > > > > I want to assign a scaled bitmap into another bit map > > how to do it.i have got a.net framework function which is working fime and > > i > > need an alternative for it to make it working for .net compactframework. > > ************************************************************ > > scaledImg = new > > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > > > > ************************************************************ > > > > How can this be done. > > > > regards > > > > Naveem > > > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
The function I sent you will scale the bitmap for you, it is the only way to
do it the compact framework (without writing your own scaling code that is). scale = value; Bitmap img = ....; your original bitmap here Bitmap scaledImg = new Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); Graphics g = Graphics.FrimImage(scaledImg); g.DrawImage(img, new Rectangle(0,0,scaledImg.Width,scaledImg.Height), new Rectangle(0,0,img.Width,img.Height), GraphicsUnit.Pixel) convertToGrayScale(); "Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message news:B6AD9ACC-A511-4E34-8BC2-A418353348C5@microsoft.com... > No this is not the thing i want, i feel your are not able to get what i am > really asking for. > > i have a function were image is scaled in .net frameworkthat function is > written as this > ********************************************************** > were scale is 1.0; > scale = value; > Bitmap scaledImg = new > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > convertToGrayScale(); > > ********************************************************** > Now i want to write this function in comapct frame work . as from here the > value of width and height goes to convertto grayscale function which is > like > this > > > > ************************************************************ > > > protected void convertToGrayScale() > { > Color col; > int gray; > for (int l = 0; l<scaledImg.Width; l++) > for (int c = 0; c<scaledImg.Height; c++) > { > col = scaledImg.GetPixel(l,c); > gray = (int)(0.32f * col.R + 0.5f * col.G + 0.18f* col.B); > scaledImg.SetPixel(l,c,Color.FromArgb(gray, gray, gray)); > > } > > > } > *************************************************************** > > if i am passing like this in compactframework > > ********************************************************** > Bitmap scaledImg = new Bitmap(img); > ********************************************************* > the values passing to convert to gray function are wrong. > so i hardly get correct results. > > So please teelme alternative for this a. > > Regards > > Naveen > > "Joseph Byrns" wrote: > >> Is this what you want? >> >> >> >> Dim b As New Bitmap(x, y) >> >> Dim g As Graphics = Graphics.FromImage(b) >> >> g.DrawImage(AnotherBitmap, destinationRectangle, SourceRectangle, >> GraphicsUnit.Pixel) >> >> >> >> "Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message >> news 613F3FA-A570-4EFB-9BE6-45E8AFBBCF9D@microsoft.com...>> > Sir, >> > >> > I want to assign a scaled bitmap into another bit map >> > how to do it.i have got a.net framework function which is working fime >> > and >> > i >> > need an alternative for it to make it working for .net >> > compactframework. >> > ************************************************************ >> > scaledImg = new >> > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); >> > >> > ************************************************************ >> > >> > How can this be done. >> > >> > regards >> > >> > Naveem >> >> >> |
|
|
|
#5 |
|
Guest
Posts: n/a
|
Sir the function you have sent me is not working, this part in the function is not working as it shows error bitmap does not take three arguments,I have tried it before also.for this function i need alternative ********************************************************** Bitmap scaledImg = new Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); ************************************************************ Regards Naveen scale = value; Bitmap img = ....; your original bitmap here Bitmap scaledImg = new Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); "Joseph Byrns" wrote: > The function I sent you will scale the bitmap for you, it is the only way to > do it the compact framework (without writing your own scaling code that is). > > scale = value; > Bitmap img = ....; your original bitmap here > Bitmap scaledImg = new > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > Graphics g = Graphics.FrimImage(scaledImg); > g.DrawImage(img, new Rectangle(0,0,scaledImg.Width,scaledImg.Height), new > Rectangle(0,0,img.Width,img.Height), > GraphicsUnit.Pixel) > > convertToGrayScale(); > > > > "Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message > news:B6AD9ACC-A511-4E34-8BC2-A418353348C5@microsoft.com... > > No this is not the thing i want, i feel your are not able to get what i am > > really asking for. > > > > i have a function were image is scaled in .net frameworkthat function is > > written as this > > ********************************************************** > > were scale is 1.0; > > scale = value; > > Bitmap scaledImg = new > > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > > convertToGrayScale(); > > > > ********************************************************** > > Now i want to write this function in comapct frame work . as from here the > > value of width and height goes to convertto grayscale function which is > > like > > this > > > > > > > > ************************************************************ > > > > > > protected void convertToGrayScale() > > { > > Color col; > > int gray; > > for (int l = 0; l<scaledImg.Width; l++) > > for (int c = 0; c<scaledImg.Height; c++) > > { > > col = scaledImg.GetPixel(l,c); > > gray = (int)(0.32f * col.R + 0.5f * col.G + 0.18f* col.B); > > scaledImg.SetPixel(l,c,Color.FromArgb(gray, gray, gray)); > > > > } > > > > > > } > > *************************************************************** > > > > if i am passing like this in compactframework > > > > ********************************************************** > > Bitmap scaledImg = new Bitmap(img); > > ********************************************************* > > the values passing to convert to gray function are wrong. > > so i hardly get correct results. > > > > So please teelme alternative for this a. > > > > Regards > > > > Naveen > > > > "Joseph Byrns" wrote: > > > >> Is this what you want? > >> > >> > >> > >> Dim b As New Bitmap(x, y) > >> > >> Dim g As Graphics = Graphics.FromImage(b) > >> > >> g.DrawImage(AnotherBitmap, destinationRectangle, SourceRectangle, > >> GraphicsUnit.Pixel) > >> > >> > >> > >> "Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message > >> news 613F3FA-A570-4EFB-9BE6-45E8AFBBCF9D@microsoft.com...> >> > Sir, > >> > > >> > I want to assign a scaled bitmap into another bit map > >> > how to do it.i have got a.net framework function which is working fime > >> > and > >> > i > >> > need an alternative for it to make it working for .net > >> > compactframework. > >> > ************************************************************ > >> > scaledImg = new > >> > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > >> > > >> > ************************************************************ > >> > > >> > How can this be done. > >> > > >> > regards > >> > > >> > Naveem > >> > >> > >> > > > |
|
|
|
#6 |
|
Guest
Posts: n/a
|
There is no need to ask the same question twice. Christian Schwarz gave
you the idea yesterday. Here you are the complete list: Bitmap scaledImg = ScaleBitmap(sourceBitmap, 0.5f, 0.5f); .... public Bitmap ScaleBitmap(Bitmap src, float xscale, float yscale) { Bitmap res = new Bitmap((int)(src.Width*xscale), (int)(src.Height*yscale)); using (Graphics g = Graphics.FromImage(res)) { g.DrawImage(src, new Rectangle(0, 0, res.Width, res.Height), 0, 0, src.Width, src.Height, GraphicsUnit.Pixel, new System.Drawing.Imaging.ImageAttributes()); } return res; } -- Sergey Bogdanov [.NET CF MVP, MCSD] http://www.sergeybogdanov.com Naveen koul wrote: > Sir the function you have sent me is not working, this part in the function > is not working as it shows error bitmap does not take three arguments,I have > tried it before also.for this function i need alternative > ********************************************************** > > Bitmap scaledImg = new > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > > > ************************************************************ > Regards > > Naveen > > scale = value; > Bitmap img = ....; your original bitmap here > Bitmap scaledImg = new > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > "Joseph Byrns" wrote: > > >>The function I sent you will scale the bitmap for you, it is the only way to >>do it the compact framework (without writing your own scaling code that is). >> >>scale = value; >>Bitmap img = ....; your original bitmap here >>Bitmap scaledImg = new >>Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); >>Graphics g = Graphics.FrimImage(scaledImg); >>g.DrawImage(img, new Rectangle(0,0,scaledImg.Width,scaledImg.Height), new >>Rectangle(0,0,img.Width,img.Height), >>GraphicsUnit.Pixel) >> >>convertToGrayScale(); >> >> >> >>"Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message >>news:B6AD9ACC-A511-4E34-8BC2-A418353348C5@microsoft.com... >> >>>No this is not the thing i want, i feel your are not able to get what i am >>>really asking for. >>> >>>i have a function were image is scaled in .net frameworkthat function is >>>written as this >>>********************************************************** >>>were scale is 1.0; >>>scale = value; >>>Bitmap scaledImg = new >>>Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); >>>convertToGrayScale(); >>> >>>********************************************************** >>>Now i want to write this function in comapct frame work . as from here the >>>value of width and height goes to convertto grayscale function which is >>>like >>>this >>> >>> >>> >>>************************************************************ >>> >>> >>>protected void convertToGrayScale() >>>{ >>>Color col; >>>int gray; >>>for (int l = 0; l<scaledImg.Width; l++) >>>for (int c = 0; c<scaledImg.Height; c++) >>>{ >>>col = scaledImg.GetPixel(l,c); >>>gray = (int)(0.32f * col.R + 0.5f * col.G + 0.18f* col.B); >>>scaledImg.SetPixel(l,c,Color.FromArgb(gray, gray, gray)); >>> >>>} >>> >>> >>>} >>>*************************************************************** >>> >>>if i am passing like this in compactframework >>> >>>********************************************************** >>>Bitmap scaledImg = new Bitmap(img); >>>********************************************************* >>>the values passing to convert to gray function are wrong. >>>so i hardly get correct results. >>> >>>So please teelme alternative for this a. >>> >>>Regards >>> >>>Naveen >>> >>>"Joseph Byrns" wrote: >>> >>> >>>>Is this what you want? >>>> >>>> >>>> >>>>Dim b As New Bitmap(x, y) >>>> >>>>Dim g As Graphics = Graphics.FromImage(b) >>>> >>>>g.DrawImage(AnotherBitmap, destinationRectangle, SourceRectangle, >>>>GraphicsUnit.Pixel) >>>> >>>> >>>> >>>>"Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message >>>>news 613F3FA-A570-4EFB-9BE6-45E8AFBBCF9D@microsoft.com...>>>> >>>>>Sir, >>>>> > > >>>>>I want to assign a scaled bitmap into another bit map >>>>>how to do it.i have got a.net framework function which is working fime >>>>>and >>>>>i >>>>>need an alternative for it to make it working for .net >>>>>compactframework. >>>>>************************************************************ >>>>>scaledImg = new >>>>>Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); >>>>> >>>>>************************************************************ >>>>> >>>>>How can this be done. >>>>> >>>>>regards >>>>> >>>>>Naveem >>>> >>>> >>>> >> >> |
|
|
|
#7 |
|
Guest
Posts: n/a
|
Sir, Yes there was no question of posting the post twice , but the question in both post is different . in first post i forgot to mention that i dont want to draw image . I want to copy the bitmap , Again i am repeating the question. i dont want to draw the image i want to copy the bitmap. i hope my query will be bit clear now. Regards Naveen "Sergey Bogdanov" wrote > There is no need to ask the same question twice. Christian Schwarz gave > you the idea yesterday. Here you are the complete list: > > Bitmap scaledImg = ScaleBitmap(sourceBitmap, 0.5f, 0.5f); > > .... > > > public Bitmap ScaleBitmap(Bitmap src, float xscale, float yscale) > { > Bitmap res = new Bitmap((int)(src.Width*xscale), > (int)(src.Height*yscale)); > > using (Graphics g = Graphics.FromImage(res)) > { > g.DrawImage(src, new Rectangle(0, 0, res.Width, res.Height), 0, 0, > src.Width, src.Height, GraphicsUnit.Pixel, new > System.Drawing.Imaging.ImageAttributes()); > } > > return res; > } > > -- > Sergey Bogdanov [.NET CF MVP, MCSD] > http://www.sergeybogdanov.com > > > Naveen koul wrote: > > Sir the function you have sent me is not working, this part in the function > > is not working as it shows error bitmap does not take three arguments,I have > > tried it before also.for this function i need alternative > > ********************************************************** > > > > Bitmap scaledImg = new > > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > > > > > > ************************************************************ > > Regards > > > > Naveen > > > > scale = value; > > Bitmap img = ....; your original bitmap here > > Bitmap scaledImg = new > > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > > "Joseph Byrns" wrote: > > > > > >>The function I sent you will scale the bitmap for you, it is the only way to > >>do it the compact framework (without writing your own scaling code that is). > >> > >>scale = value; > >>Bitmap img = ....; your original bitmap here > >>Bitmap scaledImg = new > >>Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > >>Graphics g = Graphics.FrimImage(scaledImg); > >>g.DrawImage(img, new Rectangle(0,0,scaledImg.Width,scaledImg.Height), new > >>Rectangle(0,0,img.Width,img.Height), > >>GraphicsUnit.Pixel) > >> > >>convertToGrayScale(); > >> > >> > >> > >>"Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message > >>news:B6AD9ACC-A511-4E34-8BC2-A418353348C5@microsoft.com... > >> > >>>No this is not the thing i want, i feel your are not able to get what i am > >>>really asking for. > >>> > >>>i have a function were image is scaled in .net frameworkthat function is > >>>written as this > >>>********************************************************** > >>>were scale is 1.0; > >>>scale = value; > >>>Bitmap scaledImg = new > >>>Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > >>>convertToGrayScale(); > >>> > >>>********************************************************** > >>>Now i want to write this function in comapct frame work . as from here the > >>>value of width and height goes to convertto grayscale function which is > >>>like > >>>this > >>> > >>> > >>> > >>>************************************************************ > >>> > >>> > >>>protected void convertToGrayScale() > >>>{ > >>>Color col; > >>>int gray; > >>>for (int l = 0; l<scaledImg.Width; l++) > >>>for (int c = 0; c<scaledImg.Height; c++) > >>>{ > >>>col = scaledImg.GetPixel(l,c); > >>>gray = (int)(0.32f * col.R + 0.5f * col.G + 0.18f* col.B); > >>>scaledImg.SetPixel(l,c,Color.FromArgb(gray, gray, gray)); > >>> > >>>} > >>> > >>> > >>>} > >>>*************************************************************** > >>> > >>>if i am passing like this in compactframework > >>> > >>>********************************************************** > >>>Bitmap scaledImg = new Bitmap(img); > >>>********************************************************* > >>>the values passing to convert to gray function are wrong. > >>>so i hardly get correct results. > >>> > >>>So please teelme alternative for this a. > >>> > >>>Regards > >>> > >>>Naveen > >>> > >>>"Joseph Byrns" wrote: > >>> > >>> > >>>>Is this what you want? > >>>> > >>>> > >>>> > >>>>Dim b As New Bitmap(x, y) > >>>> > >>>>Dim g As Graphics = Graphics.FromImage(b) > >>>> > >>>>g.DrawImage(AnotherBitmap, destinationRectangle, SourceRectangle, > >>>>GraphicsUnit.Pixel) > >>>> > >>>> > >>>> > >>>>"Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message > >>>>news 613F3FA-A570-4EFB-9BE6-45E8AFBBCF9D@microsoft.com...> >>>> > >>>>>Sir, > >>>>> > > > > > >>>>>I want to assign a scaled bitmap into another bit map > >>>>>how to do it.i have got a.net framework function which is working fime > >>>>>and > >>>>>i > >>>>>need an alternative for it to make it working for .net > >>>>>compactframework. > >>>>>************************************************************ > >>>>>scaledImg = new > >>>>>Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > >>>>> > >>>>>************************************************************ > >>>>> > >>>>>How can this be done. > >>>>> > >>>>>regards > >>>>> > >>>>>Naveem > >>>> > >>>> > >>>> > >> > >> > |
|
|
|
#8 |
|
Guest
Posts: n/a
|
The code snippet from the previous post does exactly what you are
looking for. Just try to invoke this method - it will return a copy of Bitmap. I believe, I understand where you stick. The Graphics.FromImage returns something like of "Device Context" for a given Bitmap. This context is used for copying one Bitmap to another by using the Draw method. It doesn't display a Bitmap, it just makes an copy. Again, just test it. -- Sergey Bogdanov [.NET CF MVP, MCSD] http://www.sergeybogdanov.com Naveen koul wrote: > Sir, > > Yes there was no question of posting the post twice , but the question in > both post is different . in first post i forgot to mention that i dont want > to draw image . I want to copy the bitmap , > Again i am repeating the question. i dont want to draw the image i want to > copy the bitmap. > > i hope my query will be bit clear now. > > Regards > > Naveen > "Sergey Bogdanov" wrote > > >>There is no need to ask the same question twice. Christian Schwarz gave >>you the idea yesterday. Here you are the complete list: >> >>Bitmap scaledImg = ScaleBitmap(sourceBitmap, 0.5f, 0.5f); >> >>.... >> >> >>public Bitmap ScaleBitmap(Bitmap src, float xscale, float yscale) >>{ >> Bitmap res = new Bitmap((int)(src.Width*xscale), >> (int)(src.Height*yscale)); >> >> using (Graphics g = Graphics.FromImage(res)) >> { >> g.DrawImage(src, new Rectangle(0, 0, res.Width, res.Height), 0, 0, >> src.Width, src.Height, GraphicsUnit.Pixel, new >>System.Drawing.Imaging.ImageAttributes()); >> } >> >> return res; >>} >> >>-- >>Sergey Bogdanov [.NET CF MVP, MCSD] >>http://www.sergeybogdanov.com >> >> >>Naveen koul wrote: >> >>>Sir the function you have sent me is not working, this part in the function >>>is not working as it shows error bitmap does not take three arguments,I have >>>tried it before also.for this function i need alternative >>>********************************************************** >>> >>>Bitmap scaledImg = new >>>Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); >>> >>> >>>************************************************************ >>>Regards >>> >>>Naveen >>> >>>scale = value; >>>Bitmap img = ....; your original bitmap here >>>Bitmap scaledImg = new >>>Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); >>>"Joseph Byrns" wrote: >>> >>> >>> >>>>The function I sent you will scale the bitmap for you, it is the only way to >>>>do it the compact framework (without writing your own scaling code that is). >>>> >>>>scale = value; >>>>Bitmap img = ....; your original bitmap here >>>>Bitmap scaledImg = new >>>>Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); >>>>Graphics g = Graphics.FrimImage(scaledImg); >>>>g.DrawImage(img, new Rectangle(0,0,scaledImg.Width,scaledImg.Height), new >>>>Rectangle(0,0,img.Width,img.Height), >>>>GraphicsUnit.Pixel) >>>> >>>>convertToGrayScale(); >>>> >>>> >>>> >>>>"Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message >>>>news:B6AD9ACC-A511-4E34-8BC2-A418353348C5@microsoft.com... >>>> >>>> >>>>>No this is not the thing i want, i feel your are not able to get what i am >>>>>really asking for. >>>>> >>>>>i have a function were image is scaled in .net frameworkthat function is >>>>>written as this >>>>>********************************************************** >>>>>were scale is 1.0; >>>>>scale = value; >>>>>Bitmap scaledImg = new >>>>>Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); >>>>>convertToGrayScale(); >>>>> >>>>>********************************************************** >>>>>Now i want to write this function in comapct frame work . as from here the >>>>>value of width and height goes to convertto grayscale function which is >>>>>like >>>>>this >>>>> >>>>> >>>>> >>>>>************************************************************ >>>>> >>>>> >>>>>protected void convertToGrayScale() >>>>>{ >>>>>Color col; >>>>>int gray; >>>>>for (int l = 0; l<scaledImg.Width; l++) >>>>>for (int c = 0; c<scaledImg.Height; c++) >>>>>{ >>>>>col = scaledImg.GetPixel(l,c); >>>>>gray = (int)(0.32f * col.R + 0.5f * col.G + 0.18f* col.B); >>>>>scaledImg.SetPixel(l,c,Color.FromArgb(gray, gray, gray)); >>>>> >>>>>} >>>>> >>>>> >>>>>} >>>>>*************************************************************** >>>>> >>>>>if i am passing like this in compactframework >>>>> >>>>>********************************************************** >>>>>Bitmap scaledImg = new Bitmap(img); >>>>>********************************************************* >>>>>the values passing to convert to gray function are wrong. >>>>>so i hardly get correct results. >>>>> >>>>>So please teelme alternative for this a. >>>>> >>>>>Regards >>>>> >>>>>Naveen >>>>> >>>>>"Joseph Byrns" wrote: >>>>> >>>>> >>>>> >>>>>>Is this what you want? >>>>>> >>>>>> >>>>>> >>>>>>Dim b As New Bitmap(x, y) >>>>>> >>>>>>Dim g As Graphics = Graphics.FromImage(b) >>>>>> >>>>>>g.DrawImage(AnotherBitmap, destinationRectangle, SourceRectangle, >>>>>>GraphicsUnit.Pixel) >>>>>> >>>>>> >>>>>> >>>>>>"Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message >>>>>>news 613F3FA-A570-4EFB-9BE6-45E8AFBBCF9D@microsoft.com...>>>>>> >>>>>> >>>>>>>Sir, >>>>>>> >>> >>> >>>>>>>I want to assign a scaled bitmap into another bit map >>>>>>>how to do it.i have got a.net framework function which is working fime >>>>>>>and >>>>>>>i >>>>>>>need an alternative for it to make it working for .net >>>>>>>compactframework. >>>>>>>************************************************************ >>>>>>>scaledImg = new >>>>>>>Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); >>>>>>> >>>>>>>************************************************************ >>>>>>> >>>>>>>How can this be done. >>>>>>> >>>>>>>regards >>>>>>> >>>>>>>Naveem >>>>>> >>>>>> >>>>>> >>>> |
|
|
|
#9 |
|
Guest
Posts: n/a
|
Yes sorry, the line:
Bitmap scaledImg = new Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); in the example I sent should be: Bitmap scaledImg = new Bitmap((int)(img.Width*scale),(int)(img.Height*scale)); The scaling is done below that line in the g.DrawImage(...) "Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message news:946A2BE5-08FE-4EAD-9BD5-33731AA853B9@microsoft.com... > > Sir the function you have sent me is not working, this part in the > function > is not working as it shows error bitmap does not take three arguments,I > have > tried it before also.for this function i need alternative > ********************************************************** > > Bitmap scaledImg = new > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > > > ************************************************************ > Regards > > Naveen > > scale = value; > Bitmap img = ....; your original bitmap here > Bitmap scaledImg = new > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > "Joseph Byrns" wrote: > >> The function I sent you will scale the bitmap for you, it is the only way >> to >> do it the compact framework (without writing your own scaling code that >> is). >> >> scale = value; >> Bitmap img = ....; your original bitmap here >> Bitmap scaledImg = new >> Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); >> Graphics g = Graphics.FrimImage(scaledImg); >> g.DrawImage(img, new Rectangle(0,0,scaledImg.Width,scaledImg.Height), new >> Rectangle(0,0,img.Width,img.Height), >> GraphicsUnit.Pixel) >> >> convertToGrayScale(); >> >> >> >> "Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message >> news:B6AD9ACC-A511-4E34-8BC2-A418353348C5@microsoft.com... >> > No this is not the thing i want, i feel your are not able to get what i >> > am >> > really asking for. >> > >> > i have a function were image is scaled in .net frameworkthat function >> > is >> > written as this >> > ********************************************************** >> > were scale is 1.0; >> > scale = value; >> > Bitmap scaledImg = new >> > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); >> > convertToGrayScale(); >> > >> > ********************************************************** >> > Now i want to write this function in comapct frame work . as from here >> > the >> > value of width and height goes to convertto grayscale function which is >> > like >> > this >> > >> > >> > >> > ************************************************************ >> > >> > >> > protected void convertToGrayScale() >> > { >> > Color col; >> > int gray; >> > for (int l = 0; l<scaledImg.Width; l++) >> > for (int c = 0; c<scaledImg.Height; c++) >> > { >> > col = scaledImg.GetPixel(l,c); >> > gray = (int)(0.32f * col.R + 0.5f * col.G + 0.18f* col.B); >> > scaledImg.SetPixel(l,c,Color.FromArgb(gray, gray, gray)); >> > >> > } >> > >> > >> > } >> > *************************************************************** >> > >> > if i am passing like this in compactframework >> > >> > ********************************************************** >> > Bitmap scaledImg = new Bitmap(img); >> > ********************************************************* >> > the values passing to convert to gray function are wrong. >> > so i hardly get correct results. >> > >> > So please teelme alternative for this a. >> > >> > Regards >> > >> > Naveen >> > >> > "Joseph Byrns" wrote: >> > >> >> Is this what you want? >> >> >> >> >> >> >> >> Dim b As New Bitmap(x, y) >> >> >> >> Dim g As Graphics = Graphics.FromImage(b) >> >> >> >> g.DrawImage(AnotherBitmap, destinationRectangle, SourceRectangle, >> >> GraphicsUnit.Pixel) >> >> >> >> >> >> >> >> "Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message >> >> news 613F3FA-A570-4EFB-9BE6-45E8AFBBCF9D@microsoft.com...>> >> > Sir, >> >> > > >> >> > I want to assign a scaled bitmap into another bit map >> >> > how to do it.i have got a.net framework function which is working >> >> > fime >> >> > and >> >> > i >> >> > need an alternative for it to make it working for .net >> >> > compactframework. >> >> > ************************************************************ >> >> > scaledImg = new >> >> > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); >> >> > >> >> > ************************************************************ >> >> > >> >> > How can this be done. >> >> > >> >> > regards >> >> > >> >> > Naveem >> >> >> >> >> >> >> >> >> |
|
|
|
#10 |
|
Guest
Posts: n/a
|
Sir,
I tried the same thing , but when the cursor goes to the convert to grey scale function . it gives error moves to catch.were if i see img valur it shows up unfedined. i am giving the fragments of code ************************************************************ First it loads the image from here this function private void radioButton1_CheckedChanged(object sender, System.EventArgs e) { try { img = new PMImage("\\Naveen.jpg"); } catch {} if (img != null) { matchs = n.search(img); } } ********************************************************** After this function it goes to to the scaling function public float Scale { set { scale = 1.0; Bitmap scaledImg = ScaleBitmap(img, 0.5f, 0.5f); convertToGrayScale(); } } ********************************************************** From this function it enters the ScaleBitmap function which was provided by you public Bitmap ScaleBitmap(Bitmap src, float xscale, float yscale) { Bitmap res = new Bitmap((int)(src.Width*xscale),(int)(src.Height*yscale)); using (Graphics g = Graphics.FromImage(res)) { g.DrawImage(src, new Rectangle(0, 0, res.Width, res.Height), 0, 0, src.Width, src.Height, GraphicsUnit.Pixel, new System.Drawing.Imaging.ImageAttributes()); } return res; } ********************************************************** from return res function goes back to Bitmap scaledImg, from there when the function goes to convertToGrayScale(), from there the dubigguer moves to catch m and when it checks the if condition it founds the img value =undefined, so come out it and just hang up. I hope i am more clear this time Regards naveen "Joseph Byrns" wrote: > Yes sorry, the line: > > Bitmap scaledImg = new > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > > in the example I sent should be: > > Bitmap scaledImg = new > Bitmap((int)(img.Width*scale),(int)(img.Height*scale)); > > > The scaling is done below that line in the g.DrawImage(...) > > > "Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message > news:946A2BE5-08FE-4EAD-9BD5-33731AA853B9@microsoft.com... > > > > Sir the function you have sent me is not working, this part in the > > function > > is not working as it shows error bitmap does not take three arguments,I > > have > > tried it before also.for this function i need alternative > > ********************************************************** > > > > Bitmap scaledImg = new > > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > > > > > > ************************************************************ > > Regards > > > > Naveen > > > > scale = value; > > Bitmap img = ....; your original bitmap here > > Bitmap scaledImg = new > > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > > "Joseph Byrns" wrote: > > > >> The function I sent you will scale the bitmap for you, it is the only way > >> to > >> do it the compact framework (without writing your own scaling code that > >> is). > >> > >> scale = value; > >> Bitmap img = ....; your original bitmap here > >> Bitmap scaledImg = new > >> Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > >> Graphics g = Graphics.FrimImage(scaledImg); > >> g.DrawImage(img, new Rectangle(0,0,scaledImg.Width,scaledImg.Height), new > >> Rectangle(0,0,img.Width,img.Height), > >> GraphicsUnit.Pixel) > >> > >> convertToGrayScale(); > >> > >> > >> > >> "Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message > >> news:B6AD9ACC-A511-4E34-8BC2-A418353348C5@microsoft.com... > >> > No this is not the thing i want, i feel your are not able to get what i > >> > am > >> > really asking for. > >> > > >> > i have a function were image is scaled in .net frameworkthat function > >> > is > >> > written as this > >> > ********************************************************** > >> > were scale is 1.0; > >> > scale = value; > >> > Bitmap scaledImg = new > >> > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > >> > convertToGrayScale(); > >> > > >> > ********************************************************** > >> > Now i want to write this function in comapct frame work . as from here > >> > the > >> > value of width and height goes to convertto grayscale function which is > >> > like > >> > this > >> > > >> > > >> > > >> > ************************************************************ > >> > > >> > > >> > protected void convertToGrayScale() > >> > { > >> > Color col; > >> > int gray; > >> > for (int l = 0; l<scaledImg.Width; l++) > >> > for (int c = 0; c<scaledImg.Height; c++) > >> > { > >> > col = scaledImg.GetPixel(l,c); > >> > gray = (int)(0.32f * col.R + 0.5f * col.G + 0.18f* col.B); > >> > scaledImg.SetPixel(l,c,Color.FromArgb(gray, gray, gray)); > >> > > >> > } > >> > > >> > > >> > } > >> > *************************************************************** > >> > > >> > if i am passing like this in compactframework > >> > > >> > ********************************************************** > >> > Bitmap scaledImg = new Bitmap(img); > >> > ********************************************************* > >> > the values passing to convert to gray function are wrong. > >> > so i hardly get correct results. > >> > > >> > So please teelme alternative for this a. > >> > > >> > Regards > >> > > >> > Naveen > >> > > >> > "Joseph Byrns" wrote: > >> > > >> >> Is this what you want? > >> >> > >> >> > >> >> > >> >> Dim b As New Bitmap(x, y) > >> >> > >> >> Dim g As Graphics = Graphics.FromImage(b) > >> >> > >> >> g.DrawImage(AnotherBitmap, destinationRectangle, SourceRectangle, > >> >> GraphicsUnit.Pixel) > >> >> > >> >> > >> >> > >> >> "Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message > >> >> news 613F3FA-A570-4EFB-9BE6-45E8AFBBCF9D@microsoft.com...> >> >> > Sir, > >> >> > > > > >> >> > I want to assign a scaled bitmap into another bit map > >> >> > how to do it.i have got a.net framework function which is working > >> >> > fime > >> >> > and > >> >> > i > >> >> > need an alternative for it to make it working for .net > >> >> > compactframework. > >> >> > ************************************************************ > >> >> > scaledImg = new > >> >> > Bitmap(img,(int)(img.Width*scale),(int)(img.Height*scale)); > >> >> > > >> >> > ************************************************************ > >> >> > > >> >> > How can this be done. > >> >> > > >> >> > regards > >> >> > > >> >> > Naveem > >> >> > >> >> > >> >> > >> > >> > >> > > > |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

613F3FA-A570-4EFB-9BE6-45E8AFBBCF9D@microsoft.com...
