I'm working with directx and it does working only on some of the Bitmaps. Why it's not working on the others ?

The question is not so clear i will try to explain here.
I have a trackBar scroll event:
private void trackBar1_Scroll(object sender, EventArgs e)
LoadPictureAt(trackBar1.Value, sender);
ConvertedBmp = ConvertTo24(trackBar1FileInfo[trackBar1.Value].FullName);
ConvertedBmp.Save(ConvertedBmpDir + "\\ConvertedBmp.bmp");
mymem = ToStream(ConvertedBmp, ImageFormat.Bmp);
backTexture = TextureLoader.FromStream(D3Ddev, mymem);
scannedCloudsTexture = new Texture(D3Ddev, 512, 512, 1, Usage.Dynamic, Format.A8R8G8B8, Pool.Default);
timer1.Stop();
Button1Code();
timer1.Start();
b1 = ConvertedBmp;
b1.Save(ConvertedBmpDir + "\\b1.bmp");
trackBar2.Enabled = false;
if (!this.backgroundWorker1.IsBusy)
label2.Text = "מעבד נתונים";
this.backgroundWorker1.RunWorkerAsync();
else
this.backgroundWorker1.CancelAsync();
First LoadPictureAt method:
private bool LoadPictureAt(int nIndex, object c)
bool bRet = false;
if (nIndex >= 0 && nIndex < trackBar1FileInfo.Length)
if (c.Equals(trackBar1))
pictureBox1.Load(trackBar1FileInfo[nIndex].FullName);
bRet = true;
if (bitmaps != null)
if (nIndex >= 0 && nIndex < bitmaps.Length)
if (c.Equals(trackBar2))
pictureBox1.Image = bitmaps[nIndex];
bRet = true;
return bRet;
Then the ConvertTo24 method:
private Bitmap ConvertTo24(string inputFileName)
sw = Stopwatch.StartNew();
Bitmap bmpIn = (Bitmap)Bitmap.FromFile(inputFileName);
Bitmap converted = new Bitmap(bmpIn.Width, bmpIn.Height, PixelFormat.Format24bppRgb);
using (Graphics g = Graphics.FromImage(converted))
// Prevent DPI conversion
g.PageUnit = GraphicsUnit.Pixel;
// Draw the image
g.DrawImageUnscaled(bmpIn, 0, 0);
//converted.Save(outputFileName, ImageFormat.Bmp);
sw.Stop();
return converted;
Then ToStream method:
public static Stream ToStream(Image image, ImageFormat formaw)
var stream = new System.IO.MemoryStream();
image.Save(stream, formaw);
stream.Position = 0;
return stream;
What it does is taking a Bitmap image and make a doppler radar effect on it and detect color only places that there are pixels(clouds) in it.
Here is a screenshot:
You can see the doppler shape and it's moving around and highlight the places with clouds.
So when i move the trackBar1 to the left each time on another Bitmap image it's showing the doppler effect and the clouds.
The problem is with the trackBar2 scroll event:
First when i'm running my program and enteric to this new form that scan the clouds and show the doppler radar effect a backgroundworker1 is working:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
BackgroundWorker bgw = (BackgroundWorker)sender;
if (bgw.CancellationPending == true)
return;
else
while (true)
bitmaps = ImagesComparison.get_images_with_clouds(b1);
for (int i = 0; i < bitmaps.Length; i++)
bitmaps[i] = ConvertTo1or8Bit.ColorToGrayscale(bitmaps[i]);
break;
What it does is getting into bitmaps(Bitmap[])  15 new bitmaps from one given bitmap. The given bitmap is b1.
b1 i'm using it in trackBar1 scroll event.
All the new Bitmaps in bitmaps variable array are Format32bppArgb.
While i checked on my hard disk the images(GIF type) i'm using with trackBar1 are all Bit Depth 8.
The images i'm using with trackBar1 scroll event are GIF types and Bit Depth 8 on the properties.
The images i'm using in trackBar2 are Bitmaps and they are Format32bppArgb.
So first thing i thought to convert all the 15 Bitmaps in bitmaps to 8bit:
for (int i = 0; i < bitmaps.Length; i++)
bitmaps[i] = ConvertTo1or8Bit.ColorToGrayscale(bitmaps[i]);
But it didn't work it's just turning them to black gray scale colors not what i was thinking about.
In the backgroundworker completed event i'm converting the bitmaps to 24 like i'm doing with the Gifs in trackBar1 scroll event:
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
trackBar2.Enabled = true;
trackBar2.Maximum = bitmaps.Length -1;
bitmaps[0].Save(ConvertedBmpDir + "\\bitmapsfirstimage.bmp");
for (int i = 0; i < bitmaps.Length; i++)
ConvertedBitmaps.Add(ConvertTo24(bitmaps[i]));
ConvertedBitmaps[0].Save(ConvertedBmpDir + "\\ConvertedBitmapsFirstImage.bmp");
label2.Text = "עיבוד הנתונים הסתיים";
b1.Dispose();
Then in the trackBar2 scroll event:
private void trackBar2_Scroll(object sender, EventArgs e)
LoadPictureAt(trackBar2.Value, sender);
ConvertedBmp = ConvertedBitmaps[trackBar2.Value - 1];
ConvertedBmp.Save(ConvertedBmpDir + "\\ConvertedBmp.bmp");
mymem = ToStream(ConvertedBmp, ImageFormat.Bmp);
backTexture = TextureLoader.FromStream(D3Ddev, mymem);
scannedCloudsTexture = new Texture(D3Ddev, 512, 512, 1, Usage.Dynamic, Format.A8R8G8B8, Pool.Default);
timer1.Stop();
Button1Code();
timer1.Start();
The same i did with the trackBar1 scroll event.
But the result in trackBar2 i'm getting without using the grayscale convertion is this:
You can see that the color that make the scan now is more yellow or green/yellow and not the same like it is when i'm using the trackBar1.
I can't figure out where the problem is:
1. Maybe since the Bitmaps in the variable array bitmaps are all Format32bppArgb ?
2. Maybe they are Bitmaps and not Gif types like the images in trackBar1 ?
If it does working good with the gifs in trackBar1 scroll event then the whole code in the new form ScanningClouds is working fine so i will not add to here the whole ScanningClouds form code since it's long.
The problem is somewhere with the Bitmaps formas or bits in the variable bitmaps.
Maybe they are not the same or the right Bit Depth or maybe they are Bitmaps and should be Gifs.
bitmaps = ImagesComparison.get_images_with_clouds(b1);
This is the get_images_with_clouds method where i'm getting the new 15 Bitmaps.
public static Bitmap[] get_images_with_clouds(Bitmap radar_image)
int e = 0;
int f = 0;
int image_clock_area_x = 0;
int image_clock_area_y = 0;
int image_clock_area_x1 = 140;
int image_clock_area_y1 = 21;
Bitmap[] localImages;
localImages = new Bitmap[15];
Bitmap image;
image = new Bitmap(Properties.Resources.radar_without_clouds);
BitmapData bmD = null;
BitmapData bmD2 = null;
try
bmD = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite,
PixelFormat.Format32bppArgb);
bmD2 = radar_image.LockBits(new Rectangle(0, 0, radar_image.Width, radar_image.Height), ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb);
IntPtr sc0 = bmD.Scan0;
unsafe
int* p = (int*)sc0.ToPointer();
int* p2 = (int*)bmD2.Scan0.ToPointer();
for (e = image_clock_area_x; e < image_clock_area_x + image_clock_area_x1; e++)
for (f = image_clock_area_y; f < image_clock_area_y + image_clock_area_y1; f++)
Color clock_color = Color.FromArgb(p2[e + f * bmD2.Width]);
p[e + f * bmD.Width] = clock_color.ToArgb();
image.UnlockBits(bmD);
radar_image.UnlockBits(bmD2);
catch
try
image.UnlockBits(bmD);
catch
try
radar_image.UnlockBits(bmD2);
catch
int c;
for (c = 0; c < localImages.Length; c++)
localImages[c] = new Bitmap(image);
Bitmap new_image = new Bitmap(Properties.Resources.radar_without_clouds);
Bitmap new_image1 = new Bitmap(Properties.Resources.radar_without_clouds);
Bitmap localbmptest = black_and_white(new_image, radar_image);
Image image1 = black_and_white(new_image, radar_image);
image1.Save(@"c:\temp\testclouds666.jpg");
Bitmap clouds = new Bitmap(image1);
int x;
int y;
int a;
int b;
int d = 0;
Bitmap redImage;
redImage = new Bitmap(512, 512);
using (Graphics g = Graphics.FromImage(redImage))
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
g.Clear(Color.Red);
BitmapData bmData = null;
BitmapData bmData2 = null;
BitmapData bmDataArray = null;
try
bmData = clouds.LockBits(new Rectangle(0, 0, clouds.Width, clouds.Height), ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb);
bmData2 = radar_image.LockBits(new Rectangle(0, 0, radar_image.Width, radar_image.Height), ImageLockMode.ReadOnly,
PixelFormat.Format32bppArgb);
IntPtr scan0 = bmData.Scan0;
IntPtr scan02 = bmData2.Scan0;
unsafe
int* p = (int*)scan0.ToPointer();
int* p2 = (int*)scan02.ToPointer();
double h, mm;
for (d = 0; d < localImages.Length; d++)
bmDataArray = localImages[d].LockBits(new Rectangle(0, 0, localImages[d].Width, localImages[d].Height), ImageLockMode.ReadWrite,
PixelFormat.Format32bppArgb);
IntPtr scan0Array = bmDataArray.Scan0;
int* pArray = (int*)scan0Array.ToPointer();
for (a = 0; a < new_image.Width; a++)
for (b = 0; b < new_image.Height; b++)
Color color1 = Color.FromArgb(p[a + b * bmData.Width]);
Color color2 = Color.FromArgb(p2[a + b * bmData2.Width]);
if (color1.R != 0 || color1.G != 0 || color1.B != 0)
h = color2.GetHue();
mm = RadarAnalysis.Hue2MMPerHour(h);
if (mm >= treshhold_array[14 - d])
pArray[a + b * bmDataArray.Width] = color2.ToArgb();
localImages[d].UnlockBits(bmDataArray);
clouds.UnlockBits(bmData);
radar_image.UnlockBits(bmData2);
catch (Exception error)
try
clouds.UnlockBits(bmData);
catch
try
radar_image.UnlockBits(bmData2);
catch
try
localImages[d].UnlockBits(bmDataArray);
catch
Logger.Write("Error Exception ==> " + error);
MessageBox.Show("Error Exception ==> " + error);
return localImages;
I think not sure but i think the problem is that the images on my hard disk i'm using with the trackBar1 scroll event are Gif type and the images i'm using with the trackBar2 scroll event are 15 Bitmaps.

Hi,
"But it didn't work it's just turning them to black gray scale colors not what i was thinking about."
If you want it to be colored, you'll need to create a color-palette for the 8bppIndexed bitmaps. The keyword for this process is "Color-Quantization".
The whole yellow-green pie you get is from the wrong format. If you convert the 32bpp bitmaps to 24 bpp bitmaps, you loose the alpha channel ("transparency"). You can manually set one color to "transparent" with the mMakeTransparent-method
of the Bitmap class, or simply use gif-images (they are 8bpp with a transparent "key"-color)
Regards,
  Thorsten

Similar Messages

  • HT4623 My iPad 2 audio only works with headphones and orientation does not work at all

    My iPad 2 volume button does not work with the integrated speakers of my iPad, once a headphone is connected to the jack output of my iPad the OSD volume displays fine and works to the external headphone but once the headphone jack is removed, there is no more a volume bar and the side volume buttons don't work at all, this has affected the screen orientation as well, screen does not orientate  as well,
    Please help

    If you deleted files from the operating system, you wrecked your installation and the first thing you need to do is either restore those files from a backup or reinstall the OS. Doing that is never the solution to any problem. Back up all data before making any changes.

  • Centering a page on the screen, why's it not working??

    Hi,
    I'm trying to centre my whole site so that it appears in the centre of the screen, no matter what size of screen it's being viewed on.
    I've had a look at other messages about this, and thought I'd done what they said but it's not working.
    I'm using Dreamweaver, and in the CSS rule definition for the DIV tag called #ContainerArea I've set Type = absolute, Height = Auto, Left & Right Placements = auto and Top & Bottom Placements = 0
    When I also change the text alignment to centre, this then centres all the text within the 'container area' but the actual area itself is still left aligned on my screen.
    It's not live, still just on my hard drive, so I can't include any links.
    Can anyone help - please?
    Thanks very much,
    Nicola

    Centered Fixed-width layout
    http://alt-web.com/TEMPLATES/CSS2-Centered-Page.shtml
    Centered Liquid-width layout
    http://alt-web.com/TEMPLATES/CSS2-Liquid-Page.shtml
    View Page Source to see the underlying code.
    Nancy O.
    Alt-Web Design & Publishing
    http://alt-web.com

  • I cannot get my @ button to work on the iMac why is this not working?

    Cant get the @ button on my iMac to wwork is there another way to get it to work other than the usual way of shift up and @

    If you have access to another keyboard, you could see if the issue is really in that,
    or if the problem could have some other cause... Even a PC keyboard may help
    to troubleshoot this one aspect. I try to always have a spare USB keyboard/mouse.
    Not sure if you could re-assign other keys, such as the F_ keys across the top, to
    have a different one for the @ symbol. There is a code for each one of those items
    and you could use it, or have a text document handy to copy-paste that one item.
    And if you have an antique iMac, or a newer intel-based one, they have different
    operating systems; and troubleshooting may take on different dimensions, too.
    So advice and results may vary depending on hardware & software in use.
    Good luck & happy computing!

  • Please check the code why it is not working

    I am a new java servlets and jsp learner. I am running below example of session in Tomcat and "AccessCount" supposed to be increased by one value whenever servelet is refereshed. But I am always getting 0 value even after refereshing it.
    I will appreciate your help.
    =======================================================
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.net.*;
    import java.util.*;
    /** Simple example of session tracking. See the shopping
    * cart example for a more detailed one.
    public class ShowSession extends HttpServlet {
    public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = "Session Tracking Example";
    String heading;
    HttpSession session = request.getSession(true);
    // Use getAttribute instead of getValue in version 2.2.
    Integer accessCount = (Integer)session.getAttribute("accessCount");
    if (accessCount == null) {
    accessCount = new Integer(0);
    heading = "Welcome, Newcomer";
    } else {
    heading = "Welcome Back";
    accessCount = new Integer(accessCount.intValue() + 1);
    // Use setAttribute instead of putValue in version 2.2.
    session.setAttribute("accessCount", accessCount);
    out.println("<html><h1>" + title + "</h1>" +
    "<BODY BGCOLOR=\"#FDF5E6\">\n" +
    "<H1 ALIGN=\"CENTER\">" + heading + "</H1>\n" +
    "<H2>Information on Your Session:</H2>\n" +
    "<TABLE BORDER=1 ALIGN=\"CENTER\">\n" +
    "<TR BGCOLOR=\"#FFAD00\">\n" +
    " <TH>Info Type<TH>Value\n" +
    "<TR>\n" +
    " <TD>ID\n" +
    " <TD>" + session.getId() + "\n" +
    "<TR>\n" +
    " <TD>Creation Time\n" +
    " <TD>" +
    new Date(session.getCreationTime()) + "\n" +
    "<TR>\n" +
    " <TD>Time of Last Access\n" +
    " <TD>" +
    new Date(session.getLastAccessedTime()) + "\n" +
    "<TR>\n" +
    " <TD>Number of Previous Accesses\n" +
    " <TD>" + accessCount + "\n" +
    "</TABLE>\n" +
    "</BODY></HTML>");
    /** Handle GET and POST requests identically. */
    public void doPost(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    doGet(request, response);
    ========================================================

    Change the code
    HttpSession session =
    request.getSession(true);AS
    HttpSession session =
    request.getSession(false);If you pass "false", then the Session is not created.
    If you pass "true" the session is always created
    new.
    Thanks and regards,
    Pazhanikanthan. PI dont think that's correct -
    1. request.getSession(false) returns a Session object if one exists.
    2. request.getSession(true) creates a new Session object if it doesnt exist or returns the reference to the existing object if the request is part of an valid session.
    OP, check with default session-timeout values in web.xml
    Ram.

  • How to make the mobile application work with firewall and anti-virus ON

    Hi,
    I keep on receiving internal processing error when i try to login sap mobile solution 1.3.0 on my ipad and i was provided a solution, that is to turn off my firewall and antivirus. I works by turn off both of it but i cant possible turn of the firewall and antivirus on the server.
    Can anyone guide me how to make the mobile application work with firewall and anti-virus ON
    Thank you

    Dear Rajesh,
    Create a policy in your fire wall to allow the port to send and receive data.
    I believe the port for the mobile should be port 8080 and 8443.
    And your license server port 30000 and 30001
    nd.Q

  • I am running an Apple imac G-5 with OS 10.5.8. I am getting the message that my version of Safari is no longer working. I downloaded a newer version of Safari and I got the message that it would not work with my OS 10.5.8. Does any one have a suggest

    I am running an Apple imac G-5 with OS 10.5.8. Processor: 2 GHz. Memory: 2 GB DDR SDRAM.  I am getting the message that my version of Safari is no longer working. I downloaded a newer version of Safari and I got the message that it would not work with my OS 10.5.8. Does any one have a suggest

    Your post somehow found its way to a little-viewed forum for an obsolete Apple productivity program. I have asked the Hosts to move you to a more active and appropriate forum for your product.

  • I have an older iMac 5,1 and the disc drive no longer works. I was hoping that I could the Apple USB super drive as a replacement, but the info on the super drive page says compatible with iMac 2012 or later. Does anyone know why it would not work for me?

    I have an older iMac 5,1 and the disc drive no longer works. I was hoping that I could the Apple USB super drive as a replacement, but the info on the super drive page says compatible with iMac 2012 or later. Does anyone know why it would not work for me?

    A reply to similar question (Q & As , in product page Apple Store) says:
    "...dissable the internal reader hardware from devices setup. Then plug the external usb superdrive and that's it."  Answered by Enrique T from Lima Oct  25 2013.
    If you can locate an external Apple USB 'Air" superdrive for earlier model MacBook Air, that should work. The newer one for the Air is the same as for iMac, now.
    You may be able to use other brands of external USB optical drive with your older intel-based iMac, as some of them function capably. A few should also be able to see system discs or other bootable utilities on DVD.
    Hopefully this helps.
    Good luck & happy computing!

  • Internal Microphone not working with Quicktime and some other apps, yet it does for Skype.

    Internal Microphone not working with Quicktime and some other apps, yet it does for Skype. 
    Microphone works fine with Quictime on another mac, so I do know how to use it. The one where it is not working (A) had an external microphone and camera attached earlier, and indeed it does work with that external microphone, but not with the internal microphone selected; and (B) had RealPlayer installed previously.
    Any suggestions, please?

    Hi,
    Download Audio driver from here.
    Intructions how to install it in Vista/Win7.
    Extract this driver with Winrar.
    Open Device manager and expand the Sound, video and game controllers section.
    Right click on Either the High Definition Audio Device if you have the generic Microsoft drivers, or the Conexant High Definition SmartAudio 221 if you have older Conexant drivers and choose "Update Driver Software..."
    Click Browse my computer for driver software, then click "Let me pick from a list of device drivers on my computer"
    Click "Have Disk..." then Browse to the folder where the drivers were extracted  .......\V64 for 64-bit Vista/Win7. Click OK.
    Select one of the "Conexant High Definition SmartAudio 221" models in the list, there will be multiple identical entries.
    Click Next, and you're done.
    I'm not sure which one from the list will work for You.
    This drivers weren't test. So if You will try them and it will work for You let us now about.
    ** Say thanks by clicking the "Thumb up" icon which is on the left. **
    ** Make it easier for other people to find solutions, by marking my answer with "Accept as Solution" if it solves your issue. **

  • I want to ask that i have passed my 10th and i am doing diploma in Mechanical Engineering. So i want to work with apple and wants to lean more from them. So how i can this company as a studying student?

    I want to ask that i have passed my 10th and i am doing diploma in Mechanical Engineering. So i want to work with apple and wants to lean more from them. So how i can this company as a studying student?

    [http://support.mozilla.com/en-US/kb/Managing+file+types]

  • [svn:fx-trunk] 5019: ASDoc updates to indicate that some Halo containers do not work with the Spark equiv (ControlBar does not work with Spark Panel/ AppControlBar does not work with Spark Application), and indicate that Canvas, Box, Tile, Panel have Spa

    Revision: 5019
    Author: [email protected]
    Date: 2009-02-19 13:17:21 -0800 (Thu, 19 Feb 2009)
    Log Message:
    ASDoc updates to indicate that some Halo containers do not work with the Spark equiv (ControlBar does not work with Spark Panel/AppControlBar does not work with Spark Application), and indicate that Canvas, Box, Tile, Panel have Spark equivs
    QE Notes: None
    Doc Notes: None
    Bugs: -
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/Accordion.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/ApplicationControlBar.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/Box.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/Canvas.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/ControlBar.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/HBox.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/Panel.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/TabNavigator.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/Tile.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/VBox.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/ViewStack.as

    Hi DST
    This is a great effort and gesture. thank you on behalf of all the newbies.
    PJ

  • HT4882 hi apple it's kian ! i have mac book air with 10.7.2 version may keyboard light does'nt work with f5 and f6 ! please help me !

    hi apple it's kian ! i have mac book air with 10.7.2 version may keyboard light does'nt work with f5 and f6 ! please help me !

    Hello Kian,
    This may sound silly but if you put your hand over the isight camera, do the lights change on the keyboard?
    Ryan

  • Dm4-1060us laptop SD Card Reader 5-in-1 question. Does it work with SDHC and SDXC memory cards?

    dm4-1060us laptop SD Card Reader 5-in-1 question. Does it work with SDHC and SDXC memory cards?

    This cart reader is a kind of multi card reader and you can use different cards with it. In my opinion every multi device should be used very, but very gently. I do not know what happened exactly in your case but maybe you have damaged something inside.
    Try to restart your notebook and use other SD card to check if everything works well. Please do it very gently and if you see something is wrong stop with inserting the card.
    I use 1 GB SD card on my A200 without any problems.
    In my opinion you should check notebook by technician.
    Bye and good luck!

  • Does Production Premium CS6 work with Maverick and the new iMacs

    Does Production Premium CS6 work with Maverick and the new i Macs

    Thankx for your reply. I saw the Apple tech note but that's what Apple says. I just want to know from users who experienced the thing if it really works.
    It doesn't seem so simple if you believe what this site tells (sorry it's in French):
    http://www.macquebec.com/spip.php?article4146
    So: BootCamp worse than the Beta?

  • Does Creative Cloud work with InDesign and linked files?

    Does Creative Cloud work with InDesign and linked files?

    This will work for online storage.
    The preview you will see on the website but will be what you see on your desktop if the the folder was missing. If you want someone else to be able to see a preview online to give comment feedback you could export out a PDF file of the work-in-progress and upload it.
    If you just want to work on the project at different locations it might be easier to zip up everything into a single file and upload it. Then download it onto the computer where you want to work and unzip it.

Maybe you are looking for