لمياء
24-12-2004, 01:36 PM
.. مساؤكم بركات يوم و ليلة الجمعة ..
.. هل هناك من خبير في البرمجة بلغة الجافا و التعامل مع الصور image من خلالها .. ؟؟
.. لدينا مشكلة "كبيــــــــــــــــــرة" في هذا المجال و محتاجة لحل سريع ..
.. صادق الوّد ..
لمياء
25-12-2004, 05:22 PM
.. مساؤكم السعادة ...
.. استطعت أن أحصل على المساعدة و لله الحمد ..
.. من منتدى أجنبي جاءني الحل الكامل و الوافي في سويعات معدودة ..
.. أستغرب من الحال هنا ..
.. و أتمنى أن يرجع السبب إلى تكاسل .. أو عدم تخصص .. لا .. جهلاً ..
.. فإن كان جهلاً .. فهو مشكلة .. أو .. مصيبة ..
.. أرق تحية ..
سنـاري
25-12-2004, 10:37 PM
الاخت الكريمة لمياء
اتمنى ان تشرحي لنا مشكلتك
ثم تضعي لنا الحل الذي حصلتِ عليه من المنتدى الاجنبي
:p
Mr.Kiady
25-12-2004, 11:40 PM
بالنسبة لي جهل ,,, :(
لكني اعرف
HTML
PHP
C++
وهالحين أدرس الأسمبلي ,,,
وأنا واثق تماما انه اكيد بمنتدانا من يعرف للجافا بس تعرفين انه الان فتره اختبارات
بطران
26-12-2004, 02:48 AM
السلام عليكم ورحمة الله وبركاته
,,,
توقعت الموضوع له أسبوع ما أحد جاوب عليه ,,,
29 ساعة تقريبا ,, وكتبتي إنك وجدتي الحل
بالنسبة لي لم أطلع على السؤال..
أولاً : لأنه لا يوجد سؤال كل الموجود إنه مطلوب واحد يعرف جافا.
ثانياً : لأني لم أدخل المنتدى خلال الـ 48 ساعة الماضية.
*******
ثالثاً : جميعنا هنا لنستفيد من بعض أولاً و لنخدم بعضنا ثانياً .. و نحن لا نطالب بعضنا بحل مشاكلنا كلها وإنما المساعدة قدر الإمكان.
رابعاً : أؤمن كمتخصص أن الجافا ليست كل الدنيا و أن هناك من الأدوات البرمجية ما يغني عنها. كما أؤمن بوجود مرض غير طبيعي اسمه (غرور الجافا) يصاب به من يبرمج بهذه اللغة لأكثر من 6 أشهر.
أخيراً: من باب المجاملة لنا (" معشر جهال الجافا ") دعينا نرى الجواب و قبله السؤال.
******************
تحياتي ,بطران
ملاحظة:
أنا أعرف لغة الجافا ولكن ليست في قائمة إهتماماتي و لا أحب البرمجة بها ؛ ولكني ( ومثلي كثير ) نعرف اين نجد الحلول المتخصصة في لغة الجافا.
عذراً على الإطالة . . . .
لمياء
26-12-2004, 07:38 PM
.. مساؤكم السعادة ..
.. لو كنتُ أدري أنني بكتابة هاتين الكلمتين ستأتي الردود .. لكنت كتبتها منذ زمن :headshak: :p ..
.. وضعت المشكلة في خمس منتديات أحدهما عربي متخصص في البرمجة .. و من ثم "سألت" إن كان أحد يعرف الجافا في المنتدى هنا ..
.. وضعتها ظهر الجمعة .. و حين عدت فترة العصر لأرى الردود .. وجدتهم في المنتدى الأجنبي قد قدمو لي الحل بالشرح المستفيض في منتديين بأكثر من طريقة ..
.. تمنيتُ أنني لم أحصل على الإجابة من المنتديات العربية بسبب تكاسل لأن مسألة الجهل ستكون صعبة ..
.. و على فكرة أنا مبتدئة جداً جداً في الجافا و لا أفقه فيها الكثير .. و ليست لغة برمجتي الأولى و لم أستخدمها إلا لأن الأستاذ فرضها علينا .. لا أكثر و لا أقل ..
.. لذا أنا من.. "معشر جهال الجافا " .. أيضاً .. أخي بطران .. !! .. و قد كتبت لماذا لا أستطيع استخدام الأدوات البرمجية الأخرى ..
.. سناري .. Mr.Kiady .. بطران ..
.. هذه هى المشكلة و الحل .. ليس من مجال المجاملة بطران إنما من باب العلم ..
Lamia:
Good Day Dear ALL,
I'm a very newbie in using Java, but I did good in coding my project till I stuck with images
I have the following code:
int rawHeight = 256;
int rawWidth = 256;
int [][] MyPixels = new int[rawWidth][rawHeight];
for(int i = 0; i < (rawWidth);i++){
for(int j = 0; j < (rawHeight);j++) {
MyPixels[i][j] = MyPixels[i][j] + (i*j) + 100;
}
}
How to represent "MyPixels" array as an image ; assume that the content of each MyPixel[i][j] is a color of type integer??
sushi-one :
You just need to create an image of your pixel array using "createImage" and "MemoryImageSource" :) :
public Image generateImage() {
int rawHeight = 256;
int rawWidth = 256;
int[] myPixels = new int[rawWidth * rawHeight];
for (int y = 0; y < rawHeight; y++) {
for (int x = 0; x < rawWidth; x++) {
myPixels[y * rawWidth + x] = ((y ^ x) << 24) | ((y ^ x) << 16) | ((y ^ x) << 8);
}
}
return (this.createImage(new MemoryImageSource(rawWidth, rawHeight, myPixels, 0, rawWidth)));
}
merry x-mas btw!:)
Thank you very much sushi-one :)
i tried your method and it works,
but I have some questions :
I stored my values ( pixels) in int[] myPixels and I already have values there, for example myPixels[11] = 125,
what is the purpose of ((y ^ x) << 24) | ((y ^ x) << 16) | ((y ^ x) << 8); ?
and what are 24,16,8 ??
SamLowry :
Not sure if you know this, so I'll explain anyway:
A color can be decomposed in 3 components: Red, Green and Blue. All colors we see can be described as "that much of Red, that much of Green and that much of Blue". The amount of each color you take is represented as a byte (range 0-255), so if you want black, you take 0 Red, 0 Green, 0 Blue. If you want pure red, 255 Red, 0 Green, 0 Blue. If you want to mix Red and Green (which would give yellow I think) you would take 255 Red, 255 Green and 0 Blue. Light Gray would be 192 R, 192 G, 192 B, etc.
There's also a 4th component, the alpha channel, which is used for other purposes, and should be 255 for now.
These 4 components can be encoded in a integer as follows:
int colorValue = (255 << 24) | (r << 16) | (g << 8) | b;
(What happens here is that you divide the integer in 4 bytes, each byte representing one component. The << operator moves the values around in the integer. So what that line of code means is "take value 255, and move it 3 bytes (=24 bits) to the left, then take the red component, move it 2 bytes to the left, so that it's next the the 255, etc.")
About that ((y ^ x) << 24) | ((y ^ x) << 16) | ((y ^ x) << 8), it fills the image with gray pixels (light gray, dark gray, ... randomly over the image). I don't think that's what you want.
Since you have a 2D array, and the MemoryImageSource wants a 1D array, I would suggest that you modify your code so that you immediately work with a 1D array.
int rawHeight = 256;
int rawWidth = 256;
int[] MyPixels = new int[rawWidth * rawHeight];
for(int i = 0; i < rawWidth; i++){
for(int j = 0; j < rawHeight; j++) {
MyPixels[j * rawWidth + i] = MyPixels[j * rawWidth + i] + (i*j) + 100;
}
}
Haven't tested it, but it should work. It can also be optimised a bit, but I'll leave your code like that, so that it's more easily recognizable.
Lamia:
Thank you very much SamLowry;
Your explanation made the picture much more clear.
Still one point left, what about if I want to save the image?
Saving can be done in a lot of ways. I'll make the assumption that you just want to write your image to a known format so that other people can easily access it.
I've just tested this approach, it seems to work:
construct a BufferedImage instance, fill in the pixel data and use ImageIO to save it to a file.
int[] pixelData; // contains your pixels in a 1D array
int width, height; // I assume these variables contain the image's width & height
/* Create the buffered image instance */
BufferedImage image =
new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
/* Set color data */
image.setRGB(0, 0, width, height, pixelData, 0, width);
/* Save it to file */
try
{
ImageIO.write( image, "PNG", new File("output.png") );
}
catch ( IOException e )
{
// Something bad happened
System.out.println(e);
}
I've tried other formats, only JPG seems to work (but produces the wrong colors...).
.. هذه هى المشكلة و حلها ..
.. و السموحة يا اخوان .. :)
بطران
26-12-2004, 09:35 PM
السلام عليكم ورحمة الله وبركاته
شكرا جزيلا على السؤال و إجابته ..
سؤال جميل جداً, اتمنى لكِ التوفيق.
*ملاحظة بسيطه,, وأخيرة:
عندما تبحثين عن شيء عاجل و مُلِح فإن الغالبية من المختصين العرب (وهم قلة) بالكاد يدخلون إلى المواقع المتخصصة بسبب الظروف العملية. أما الهواة فلا أكاد أعرف عربيا يهوى البرمجة دون أن يكون متخصص، على عكس الموجود في أنحاء مختلفة من العالم.
تحياتي, بطران
سنـاري
28-12-2004, 08:15 AM
can you specify which forums you think it's the best for programmer
specially who works in
1- Oracle ... SQL, PL\SQL
2- V.B
and if you know any websites for network mintinance and truobleshoting
don't think twice before you post it here
regards
:p