Will only work properly with MIDP 2.0
import javax.microedition.lcdui.Image;
public class Resizer {
// fixed point constants
private static final int FP_SHIFT = 13;
private static final int FP_ONE = 1 << FP_SHIFT;
private static final int FP_HALF = 1 << (FP_SHIFT - 1);
// resampling modes - valid values for the mode parameter of resizeImage()
// any other value will default to MODE_BOX_FILTER because of the way the conditionals are set in resizeImage()
public static final int MODE_POINT_SAMPLE = 0;
public static final int MODE_BOX_FILTER = 1;
/**
* getPixels
* Wrapper for pixel grabbing techniques.
* I separated this step into it's own function so that other APIs (Nokia, Motorola, Siemens, etc.) can
* easily substitute the MIDP 2.0 API (Image.getRGB()).
* @param src The source image whose pixels we are grabbing.
* @return An int array containing the pixels in 32 bit ARGB format.
*/
static int[] getPixels(Image src) {
int w = src.getWidth();
int h = src.getHeight();
int[] pixels = new int[w * h];
src.getRGB(pixels,0,w,0,0,w,h);
return pixels;
}
/**
* drawPixels
* Wrapper for pixel drawing function.
* I separated this step into it's own function so that other APIs (Nokia, Motorola, Siemens, etc.) can
* easily substitute the MIDP 2.0 API (Image.createRGBImage()).
* @param pixels int array containing the pixels in 32 bit ARGB format.
* @param w The width of the image to be created.
* @param h The height of the image to be created. This parameter is actually superfluous, because it
* must equal pixels.length / w.
* @return The image created from the pixel array.
*/
static Image drawPixels(int[] pixels, int w, int h) {
return Image.createRGBImage(pixels,w,h,true);
}
static Image resizeImage(Image src, float factor) {
return resizeImage(src, factor, MODE_BOX_FILTER);
}
/**
* resizeImage
* Gets a source image along with new size for it and resizes it.
* @param src The source image.
* @param destW The new width for the destination image.
* @param destH The new heigth for the destination image.
* @param mode A flag indicating what type of resizing we want to do. It currently supports two type:
* MODE_POINT_SAMPLE - point sampled resizing, and MODE_BOX_FILTER - box filtered resizing (default).
* @return The resized image.
*/
static Image resizeImage(Image src, float factor, int mode) {
int srcW = src.getWidth();
int srcH = src.getHeight();
int destW = (int)(srcW * factor);
int destH = (int)(srcH * factor);
// create pixel arrays
int[] destPixels = new int[destW * destH]; // array to hold destination pixels
int[] srcPixels = getPixels(src); // array with source's pixels
if (mode == MODE_POINT_SAMPLE) {
// simple point smapled resizing
// loop through the destination pixels, find the matching pixel on the source and use that
for (int destY = 0; destY < destH; ++destY) {
for (int destX = 0; destX < destW; ++destX) {
int srcX = (destX * srcW) / destW;
int srcY = (destY * srcH) / destH;
destPixels[destX + destY * destW] = srcPixels[srcX + srcY * srcW];
}
}
}
else {
// precalculate src/dest ratios
int ratioW = (srcW << FP_SHIFT) / destW;
int ratioH = (srcH << FP_SHIFT) / destH;
int[] tmpPixels = new int[destW * srcH]; // temporary buffer for the horizontal resampling step
// variables to perform additive blending
int argb; // color extracted from source
int a, r, g, b; // separate channels of the color
int count; // number of pixels sampled for calculating the average
// the resampling will be separated into 2 steps for simplicity
// the first step will keep the same height and just stretch the picture horizontally
// the second step will take the intermediate result and stretch it vertically
// horizontal resampling
for (int y = 0; y < srcH; ++y) {
for (int destX = 0; destX < destW; ++destX) {
count = 0; a = 0; r = 0; b = 0; g = 0; // initialize color blending vars
int srcX = (destX * ratioW) >> FP_SHIFT; // calculate beginning of sample
int srcX2 = ((destX + 1) * ratioW) >> FP_SHIFT; // calculate end of sample
// now loop from srcX to srcX2 and add up the values for each channel
do {
argb = srcPixels[srcX + y * srcW];
a += ((argb & 0xff000000) >> 24); // alpha channel
r += ((argb & 0x00ff0000) >> 16); // red channel
g += ((argb & 0x0000ff00) >> 8); // green channel
b += (argb & 0x000000ff); // blue channel
++count; // count the pixel
++srcX; // move on to the next pixel
}
while (srcX <= srcX2 && srcX + y * srcW < srcPixels.length);
// average out the channel values
a /= count;
r /= count;
g /= count;
b /= count;
// recreate color from the averaged channels and place it into the temporary buffer
tmpPixels[destX + y * destW] = ((a << 24) | (r << 16) | (g << 8) | b);
}
}
// vertical resampling of the temporary buffer (which has been horizontally resampled)
for (int x = 0; x < destW; ++x) {
for (int destY = 0; destY < destH; ++destY) {
count = 0; a = 0; r = 0; b = 0; g = 0; // initialize color blending vars
int srcY = (destY * ratioH) >> FP_SHIFT; // calculate beginning of sample
int srcY2 = ((destY + 1) * ratioH) >> FP_SHIFT; // calculate end of sample
// now loop from srcY to srcY2 and add up the values for each channel
do {
argb = tmpPixels[x + srcY * destW];
a += ((argb & 0xff000000) >> 24); // alpha channel
r += ((argb & 0x00ff0000) >> 16); // red channel
g += ((argb & 0x0000ff00) >> 8); // green channel
b += (argb & 0x000000ff); // blue channel
++count; // count the pixel
++srcY; // move on to the next pixel
}
while (srcY <= srcY2 && x + srcY * destW < tmpPixels.length);
// average out the channel values
a /= count; a = (a > 255) ? 255 : a;
r /= count; r = (r > 255) ? 255 : r;
g /= count; g = (g > 255) ? 255 : g;
b /= count; b = (b > 255) ? 255 : b;
// recreate color from the averaged channels and place it into the destination buffer
destPixels[x + destY * destW] = ((a << 24) | (r << 16) | (g << 8) | b);
}
}
}
// return a new image created from the destination pixel buffer
return drawPixels(destPixels,destW,destH);
}
}
To copy above code, please open page source and CTRL-C from there.
--thgc
284 Kommentare:
«Älteste ‹Ältere 201 – 284 von 284Hello would you mind letting me know which hosting company
you're using? I've loaded your blog in 3 different internet browsers and I must say this blog loads
a lot faster then most. Can you suggest a good web hosting provider at a honest price?
Many thanks, I appreciate it!
Have a look at my web page - HTTP://www.perklife.com/index.php?do=/blog/58252/provillus-consumer-reviews-articles/
my site: Jesus
Hello, i think that i saw you visited my weblog so i came to “return the favor”.
I am trying to find things to enhance my website!I suppose its ok to use a
few of your ideas!!
My webpage ... Glory
Also see my web page: Provillus Review
If you would like to increase your familiarity just
keep visiting this web page and be updated with the most up-to-date gossip posted here.
Feel free to visit my page :: hothiphopvideosonline.com
It's a pity you don't have a donate button! I'd definitely donate to this outstanding blog! I suppose for now i'll settle
for book-marking and adding your RSS feed to my Google account.
I look forward to brand new updates and will share this website with my Facebook group.
Talk soon!
My web blog :: hothiphopvideosonline.com
Hello to all, for the reason that I am actually keen of
reading this website's post to be updated regularly. It carries nice material.
Check out my web-site - http://dhartipunjabdi.com/index.php?do=/profile-51934/info/
Hi to all, the contents present at this web page are actually awesome for people experience, well,
keep up the good work fellows.
Feel free to surf to my web site - elgg-1-8.lachakanaverde.org
Very nice write-up. I absolutely love this website.
Thanks!
Here is my blog :: Kingbio hemorrhoid relief
I know this website gives quality based articles and extra data, is
there any other web site which offers such things in quality?
Here is my blog post: http://Www.tastyzeppelin.com/blog/view/74959/best-techniques-for-stopping-baldness
My website > Phyllis
If some one desires expert view on the topic
of blogging afterward i suggest him/her to pay a visit this weblog, Keep up the
fastidious work.
my webpage :: http://more4you.ws/articles/article.php/09-03-2013Provillus-Thinning-Hair-Cure-Related-Articles.htm
I have read so many articles about the blogger lovers
but this article is actually a nice article, keep it up.
my homepage; http://www.by.dreamhosters.com/status/lorenzole
great post, very informative. I ponder why the opposite experts
of this sector don't notice this. You should proceed your writing. I'm confident, you've a great readers' base already!
Also visit my webpage ... http://www.sitelaunch.meanskreenz.us/Stop-Hereditary-Baldness--A-Provillus-Review.htm
It's very easy to find out any topic on net as compared to textbooks, as I found this post at this site.
Review my page ... http://Www.Gourmetgastronomer.com/twitter/index.php/ahpmargue
Yesterday, while I was at work, my sister stole my apple ipad and
tested to see if it can survive a thirty foot drop, just
so she can be a youtube sensation. My iPad is now broken and
she has 83 views. I know this is totally off topic but I had to share it with someone!
my webpage; Provillus Ingredients
Also see my web site - www.monroeunderwood.com
It's remarkable to pay a visit this web site and reading the views of all friends about this article, while I am also eager of getting knowledge.
My web site http://www.blo99ing.com
It's amazing in favor of me to have a web site, which is useful in favor of my experience. thanks admin
Feel free to surf to my page - http://geekmotion.com/index.php?do=/blog/10692/gotu-kola-as-treatment-for-hair-loss/
My website: Dorothy
I have read so many posts about the blogger lovers however this post is in fact
a nice post, keep it up.
My homepage; Muslimfacebook.net
Usually, the best time to expect free time on Xbox Live is when there
is a gaming event taking place (such as the launching of a new game).
This isn't anything new to the "Silver" accounts, though. Article Source: best microsoft Points generator to look for is the second type which gives more guarantee of being successful that the first or the third type and.
Feel free to surf to my website :: free microsoft points
Also see my site > microsoft points codes
Whats up this is somewhat of off topic but I was wondering if blogs use WYSIWYG editors or if you
have to manually code with HTML. I'm starting a blog soon but have no coding skills so I wanted to get guidance from someone with experience. Any help would be greatly appreciated!
Feel free to surf to my weblog www.sbwire.com
What's up colleagues, its impressive piece of writing regarding cultureand fully explained, keep it up all the time.
My web page: short term loans
My website > short term loans
Excellent post however I was wondering if you could write a litte
more on this topic? I'd be very thankful if you could elaborate a little bit more. Bless you!
Feel free to visit my site - www.sbwire.com
I think the admin of this website is in fact working hard
in support of his site, because here every data is quality based information.
Also visit my website - http://Markethealth.Blog.com/2013/03/09/specialist-skin-care-strategies-for-excellent-skin-in-your-big-day/
Hi! I just wanted to ask if you ever have any
trouble with hackers? My last blog (wordpress) was hacked and I
ended up losing a few months of hard work due to no back up.
Do you have any methods to protect against hackers?
Here is my page: http://markethealth.blog.com/2013/03/09/incidents-and-skincare-support/
This website was... how do you say it? Relevant!
! Finally I have found something which helped me.
Cheers!
Feel free to surf to my webpage - http://markethealth.blog.com/2013/03/09/specialist-skin-care-strategies-for-excellent-skin-in-your-big-day/
Also see my page: http://markethealth.blog.com/2013/03/09/incidents-and-skincare-support/
Hеу therе! Ѕοmeone in my Μyspаce group sharеd this
site with us so Ι came to tаke a look. І'm definitely loving the information. I'm book-mаrking and
will be tweеtіng this to mу folloωers!
Wonԁerful blog and fantaѕtic design and ѕtyle.
mу web blog ... instant cash loans
Every weekend і used tο paу a quick viѕіt this site, аs i want enjoyment, аs this thiѕ
web site cοnations genuinely ρleаsant funny datа too.
Also visit my weblog quick loans
This is mу first timе paу a quick
ѵіsit at here anԁ i am actually hарpy to rеad eѵerthіng at οne plaсe.
Also visit my sitе ... quick loans
There's definately a great deal to find out about this topic. I love all of the points you have made.
Feel free to visit my website; goodreads.com
What's up, its fastidious post about media print, we all be aware of media is a wonderful source of facts.
Here is my web site www.purevolume.com
Hi there everyone, it's my first go to see at this site, and post is really fruitful designed for me, keep up posting such articles.
Here is my web-site ... provillus minoxidil
obviously like your web site however you need to test the spelling on several of your posts.
Many of them are rife with spelling problems and
I to find it very bothersome to tell the reality however I'll certainly come again again.
my webpage - /blog/4574787980/Don't-Buy-Provillus-Before-reading-This-Provillus-Assessment/5197147
Greetings! Very helpful advice within this article!
It is the little changes that will make the biggest changes.
Thanks a lot for sharing!
Feel free to surf to my blog post - http://gffjgfgh.shutterfly.com
Have you ever considered about including a little bit more than just your articles?
I mean, what you say is fundamental and everything. But think about if you added some great
pictures or videos to give your posts more, "pop"!
Your content is excellent but with images and videos, this website could undeniably be
one of the greatest in its niche. Terrific blog!
My homepage: www.iccup.com
Attractive element of content. I just stumbled upon your
blog and in accession capital to assert that I get actually loved account your blog posts.
Any way I will be subscribing on your augment and even I success you get
admission to persistently quickly.
my web page - provillus
Hi! I could have sworn I've been to this website before but after browsing through some of the post I realized it's
new to me. Anyhow, I'm definitely delighted I found it and I'll be bookmarking and
checking back frequently!
Here is my blog post - http://www.purevolume.com/listeners/Jimaraq11/posts/353322/Vital+Elements+For+Swimming+Pool+Around+The+UK
Hello to all, because I am truly eager of reading this weblog's post to be updated on a regular basis. It contains pleasant information.
Feel free to visit my web-site http://www.flixya.com/blog/5215241/A-Look-At-Convenient-Swimming-Pools-Programs
I am not sure where you're getting your info, but good topic. I needs to spend some time learning more or understanding more. Thanks for excellent info I was looking for this info for my mission.
my weblog metroblog.com
Thanks , I have just been looking for info about this subject for a
while and yours is the best I've discovered so far. However, what in regards to the bottom line? Are you sure about the source?
Stop by my blog blogymate.com
If you desire to take a good deal from this post then you have
to apply such methods to your won webpage.
Check out my page provillus
This site was... how do I say it? Relevant!! Finally I have found
something that helped me. Many thanks!
Feel free to surf to my blog - foliactive y provillus
I was recommended this web site via my cousin. I am no longer
positive whether this post is written by him as no
one else recognize such designated about my difficulty.
You're wonderful! Thanks!
Have a look at my webpage ... provillus for women ingredients
It is appropriate time to make a few plans for the longer term and it's time to be happy. I've read this publish and if I may just I
want to recommend you few attention-grabbing issues
or tips. Maybe you can write next articles regarding this article.
I desire to learn even more issues about it!
Feel free to surf to my web site provillus supplement
Do you mind if I quote a couple of your posts as long as I provide credit and sources back to
your blog? My blog is in the very same niche as yours and my visitors would really benefit from some of the information
you present here. Please let me know if this alright with you.
Thanks!
Also visit my web site http://mactin2082.webgarden.com/
I am sure this paragraph has touched all the internet people, its really really good post on building up new webpage.
Also visit my blog: thuvuwwa.jimdo.com
Hi, I do think this is an excellent site. I stumbledupon it ;) I'm going to revisit once again since I bookmarked it. Money and freedom is the best way to change, may you be rich and continue to guide other people.
Also visit my site: http://www.homebasedbusinessprogram.com/
Every weekend i used to visit this site, as i wish for enjoyment, as this this website conations
really good funny data too.
My website ... http://www.iccup.com/content/blogs/A_Guide_To_Vital_Details_In_Swimming_Pools.html
I’m not that much of a online reader to be honest but your sites
really nice, keep it up! I'll go ahead and bookmark your website to come back down the road. Cheers
Feel free to visit my blog post - thuvuwwai.webs.com
I'm not sure exactly why but this blog is loading extremely slow for me. Is anyone else having this issue or is it a issue on my end? I'll check back later
and see if the problem still exists.
My blog post :: provillus for women reviews
Hey there would you mind letting me know which webhost you're working with? I've loaded your
blog in 3 completely different web browsers and I must say
this blog loads a lot quicker then most. Can you recommend a good web hosting
provider at a reasonable price? Thank you, I appreciate it!
my webpage: http://thuvuwwan.blogspot.com/2013/03/options-for-speedy-systems-in-swimming.html
WOW just what I was searching for. Came here by searching
for hair loss
Feel free to surf to my webpage provillus
Howdy! Would you mind if I share your blog with my myspace group?
There's a lot of folks that I think would really enjoy your content. Please let me know. Thank you
my web-site: http://bigcontact.com/Thuvuwwa/provillus-reviews---can-they-help-out-with-your-search-finest-hair-loss
I usually do not comment, however after reading a few of the remarks on "Resizing images".
I actually do have a few questions for you if you do not mind.
Could it be just me or does it appear like a few of these
comments appear like they are coming from brain dead individuals?
:-P And, if you are posting at other sites, I would
like to follow anything new you have to post. Could you list of all of all your public sites like your twitter feed, Facebook page or linkedin profile?
my site; http://www.iccup.com/
Hi, after reading this awesome post i am too happy to share my familiarity here with mates.
Also visit my blog: provillus for men
Amazing issues here. I'm very satisfied to peer your post. Thanks a lot and I am taking a look ahead to touch you. Will you please drop me a e-mail?
My web-site http://www.blackplanet.com/your_page/blog/view_posting.html?pid=1079335&profile_id=61836852&profile_name=Theueeak&user_id=61836852&username=Theueeak
Peculiar article, totally what I needed.
my web-site ... http://communities.bentley.com/members/thuvuwwa/default.aspx
Very rapidly this web page will be famous among all blogging
users, due to it's pleasant posts
Feel free to surf to my web-site :: www.jambase.com
Hi there, I enjoy reading all of your article post. I like to
write a little comment to support you.
Feel free to visit my weblog; thuvuwwa.skyrock.com
If some one wants to be updated with hottest technologies then he must be visit this website
and be up to date everyday.
my web site - https://mactin2082.jux.com/1055716
Wow, marvelous weblog structure! How long have you ever been running a blog for?
you made blogging glance easy. The total look of your website
is excellent, let alone the content material!
my page; tendancetv.us
Amazing things here. I'm very glad to look your article. Thank you so much and I'm
looking ahead to contact you. Will you kindly drop me a e-mail?
Check out my page - provillus before and after
I'm very pleased to uncover this web site. I want to to thank you for your time just for this fantastic read!! I definitely savored every little bit of it and i also have you saved to fav to see new information on your website.
Also visit my site - blogspot.com
Hello! Someone in my Myspace group shared this website with us so I came to look it over.
I'm definitely enjoying the information. I'm bookmarking and will be tweeting this to my followers!
Outstanding blog and wonderful design and style.
Feel free to visit my blog post: http://thuvuwwa.webobo.biz/
Thanks for sharing your thoughts about hair loss.
Regards
Look into my blog; provillus
Woah! I'm really loving the template/theme of this website. It's simple,
yet effective. A lot of times it's very difficult to get that "perfect balance" between user friendliness and visual appearance. I must say you've done
a excellent job with this. In addition, the blog loads very
fast for me on Opera. Outstanding Blog!
Also visit my web blog - http://www.blurpalicious.com/
I know thіs website pгesents quаlity ԁepеndеnt ρosts and еxtra stuff, iѕ there any оther website whiсh givеs these kinds of things in quаlіty?
Hеrе is my weblоg payday loans
This is my first time visit at here and i am genuinely impressed to read everthing at single place.
my website: http://maxzidi.xbuild.com/
Right away I am ready to do my breakfast, afterward
having my breakfast coming yet again to read further news.
Also visit my web site http://thuvuwwa.hpage.com
Hi there! I know this is somewhat off topic but I was wondering which blog
platform are you using for this site? I'm getting sick and tired of Wordpress because I've had issues with hackers
and I'm looking at options for another platform. I would be great if you could point me in the direction of a good platform.
Here is my blog post - http://thuvuwwa.webobo.biz/
Hey there exceptional blog! Does running a blog such as this require a lot of work?
I've no knowledge of computer programming but I had been hoping to start my own blog in the near future. Anyhow, if you have any ideas or tips for new blog owners please share. I know this is off topic nevertheless I simply wanted to ask. Thanks!
my web page http://www.23hq.com/Theueeak/story/10305222
What's up i am kavin, its my first occasion to commenting anyplace, when i read this paragraph i thought i could also create comment due to this brilliant article.
Here is my website; http://www.blurpalicious.com/Theueeak/the-latest-on-swift-plans-for-outdoor-pool
Hello there, just became aware of your blog through Google, and found that
it's truly informative. I'm gonna watch out for brussels.
I will appreciate if you continue this in future.
Numerous people will be benefited from your writing.
Cheers!
Here is my weblog - provillus
This post is invaluable. How can I find out more?
my website - www.keepandshare.com
continuously i used to read smaller posts that
also clear their motive, and that is also happening with this article
which I am reading at this time.
Feel free to surf to my weblog; http://www.supernova.com/Thuvuwwa/blog/1842073/Speedy-Systems-Of-Outdoor-Pool--The-Basics
After looking over a handful of the blog articles on your
website, I seriously like your way of blogging. I bookmarked it
to my bookmark webpage list and will be checking back in the near future.
Take a look at my website as well and tell me
what you think.
Here is my weblog; http://www.wecolumn.com
Keep on writing, great job!
Look into my web site: http://thuvuwwa.bravesites.com/
Hold you always mat up as if you said Webster Franklin, chair of the Tunic Formula and Visitors Authority. [url=http://www.tasty-onlinecasino.co.uk/]http://www.onlinecasinotaste.co.uk/[/url] casino online Paf reserves the proper to and let the online games get. http://www.onlinecasinoburger.co.uk/
Stretch marks are formed when fibroblasts are somehow restricted and skin vitality is not ok.
And also some of the underweight people are also such complaints.
Activity and healthy diet will help one retain firm skin tone but it can’t guarantee that cellulite won’t appear.
Also visit my site: Strecth Marks
Τhanks in suppoгt of sharing such a nіcе іdeа,
articlе is nice, thats why i have read іt fullу
Here is my page: raspberry ketone uk
Thanks for finаlly talkіng about
> "Resizing images" < Liked it!
my web site ... payԁay loans
Hey thеre! Ѕomeone in my Myspace grοup shared thiѕ ωebsіte with us so Ι
came to take a lοok. I'm definitely enjoying the information. I'm bookmarkіng аnd
will be tweеting thiѕ to mу followеrs!
Wonderful blοg and teгrific ԁesign and stуle.
Here is my wеbsite - payday loans uk
Hellо, i think that i sаw you vіsiteԁ mу web site thus i camе to “retuгn the favoг”.
I'm attempting to find things to improve my web site!I suppose its ok to use a few of your ideas!!
my website; payday loans
It enables you to fully grasp this money simply and pay it off when you get your future salary examine [url=http://www.weirdopayday.co.uk/]payday loans[/url] payday loan He is able to pay back as well as interest in time and his financial position will get much better in this time period http://www.paydayfreakuk.co.uk/
Hi theге, I enјoy rеading all of
your article. I like to ωrite a littlе comment
to support you.
Look аt my weblog :: Payday Loans
Ηello! This is my 1st commеnt herе so Ӏ just wаntеd tο give a quick shout out
anԁ tеll you I really enjoy reаding
thгough your articles. Ϲan you suggest anу οther blоgѕ/websites/foгumѕ that
cover the same subjects? Тhanκs fοг youг tіme!
my wеb site Same Day Payday Loans
Hеllо, after reаԁing this amаzing
paragraρh i am alѕo happy to share my exрerience here
with mаtes.
Feel frеe to visіt my ѕite; New Bingo Sites
Kommentar veröffentlichen